失去焦点事件代码:
public void myTextBox_LostFocus(object sender, System.Windows.Input.GestureEventArgs e)
{
string name = ((TextBox)sender).Name;
string strl = "tbox" + name.Substring(4);
TextBox text = FindTextBoxByName(strl);
text.HorizontalAlignment = HorizontalAlignment.Left;
text.Width = 50;
text.Height = 40;
}
事件调用:-
myTextBox1j.LostFocus += new EventHandler<GestureEventArgs>(myTextBox_LostFocus);
抛出以下错误:- 无法将类型“System.EventHandler”隐式转换为“System.Windows.RoutedEventHandler”
最佳答案
LostFocus
事件需要一个 RoutedEventHandler
,而不是 EventHandler
。
myTextBox1j.LostFocus += new RoutedEventHandler(myTextBox_LostFocus);
这也应该有效:
myTextBox1j.LostFocus += myTextBox_LostFocus;
关于c# - 文本框的动态失去焦点事件抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23113639/