gpt4 book ai didi

c# - 文本框的动态失去焦点事件抛出错误

转载 作者:行者123 更新时间:2023-11-30 16:59:51 29 4
gpt4 key购买 nike

失去焦点事件代码:

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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com