失去焦点事件代码:
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);
引发以下错误: - 无法隐式转换类型&#39; System.EventHandler&#39;到&#39; System.Windows.RoutedEventHandler&#39;
答案 0 :(得分:2)
LostFocus
事件需要RoutedEventHandler
,而不是EventHandler
。
myTextBox1j.LostFocus += new RoutedEventHandler(myTextBox_LostFocus);
这也应该有效:
myTextBox1j.LostFocus += myTextBox_LostFocus;