winfrom 绑定Leave 事件,怎么给绑定的方法传递参数且没有返回值

queen_exception 2017-05-18 09:57:52
/// <summary>
/// 加载页面数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Split_Load(object sender, EventArgs e)
{
var invoiceItemList = this.EditInvoice.InvoiceItemList;
int y = 30;
int index = 0;
foreach (InvoiceItem item in invoiceItemList)
{
y = (index++ + 1) * 30 + 32;
Label title = new Label() { Text = item.XMMC };
title.Location = new Point(25, y);
title.Size = new Size(120, 12);
title.TextAlign = ContentAlignment.MiddleCenter;
this.BtnPanel.Controls.Add(title);

NumericUpDown txtQuantityBox = new NumericUpDown { Name = "quantity_" + index.ToString(), Value = 0 };
txtQuantityBox.Location = new Point(160, y - 5);
txtQuantityBox.Size = new Size(115, 20);
txtQuantityBox.TextAlign = HorizontalAlignment.Right;
txtQuantityBox.Minimum = (int)0;
txtQuantityBox.Maximum = int.MaxValue;
txtQuantityBox.InterceptArrowKeys = true;
this.BtnPanel.Controls.Add(txtQuantityBox);

NumericUpDown txtAmountBox = new NumericUpDown { Name = "amount_" + index.ToString(), Value = 0 };
txtAmountBox.Location = new Point(290, y - 5);
txtAmountBox.Size = new Size(115, 20);
txtAmountBox.TextAlign = HorizontalAlignment.Right;
txtAmountBox.DecimalPlaces = 2;
txtAmountBox.Increment = 0.25M;
txtAmountBox.Minimum = (int)0;
txtAmountBox.Maximum = decimal.MaxValue;
txtAmountBox.InterceptArrowKeys = true;
this.BtnPanel.Controls.Add(txtAmountBox);
txtQuantityBox.Leave += new EventHandler(Adjusts(y));

}
}




int i = 0;
double alljshj = 0.00;
private EventHandler Adjusts(int y)
{
try
{
var height = this.Height;
var invoiceItemList = this.EditInvoice.InvoiceItemList;
i = (y - 32) / 30;
Control quantityCtl = this.BtnPanel.GetChildAtPoint(new Point(160, y - 5));
Control amountCtl = this.BtnPanel.GetChildAtPoint(new Point(290, y - 5));
amountCtl.Text = InvoiceHelper.GetDouble(double.Parse(quantityCtl.Text) * invoiceItemList[i].XMDJ).ToString();
var amountall = InvoiceHelper.GetDouble(double.Parse(amountCtl.Text));
alljshj += amountall;
this.txt_JSHJ.Text = InvoiceHelper.GetDouble(alljshj).ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
throw new NotImplementedException();
}
...全文
1108 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
queen_exception 2017-05-19
  • 打赏
  • 举报
回复
解决了: var height = ((NumericUpDown)sender).Location; 可以获取到控件的相关参数 ,从而达到传参的目的
queen_exception 2017-05-18
  • 打赏
  • 举报
回复
我是想txtQuantityBox.Leave += new EventHandler(Adjusts(参数)); Adjusts方法没有返回值 业务需求 只有在Leave 的时候调用Adjust方法
xdashewan 2017-05-18
  • 打赏
  • 举报
回复

txtQuantityBox.Leave += new EventHandler(Adjusts);
Adjusts(y);

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧