我试图从另一个类调用一个方法,但在该方法内部,从第一个类调用一个方法......我无法解释得更好,所以这就是我想要用代码做的......
我的类.cs
public static void validarCampos(object sender) {
**some code here**
}
// here, a KeyDown function calls MyHelper.cs=>TextBoxKyeDown method
private void tb_KeyDown(object sender, KeyEventArgs e)
{
(sender as TextBox).TextBoxKeyDown(e, this);
}
我的助手.cs
public static void TextBoxKeyDown(this TextBox tb, KeyEventArgs e, Control container)
{
switch (e.KeyCode)
{
case Keys.Enter:
case Keys.Add:
tb.ZeroFill(e);
// I want to call MyClass.cs=>validarCampos(tb);
// here, before it moves to next TB, because on
// validarCampos(tb) I can tell if the next TB is
// enabled or not, if I do not call it HERE
// when I press ENTER or ADD, it wont move next TB
// until I press it twice...
e.SuppressKeyPress = true;
container.SelectNextControl(tb, true, true, false, true);
break;
case Keys.Decimal:
if ((tb.Tag as string) == "importe")
{
e.SuppressKeyPress = true;
container.SelectNextControl(tb, true, true, false, true);
}
break;
case Keys.Subtract:
e.SuppressKeyPress = true;
container.SelectNextControl(tb, false, true, false, true);
break;
}
}
真的很抱歉解释,如果你需要更多线索告诉我......我不粘贴整个valdarCampos代码,因为它是〜140行......它只是检查TextBoxes的内容并确定哪些是启用或禁用取决于结果...