[英]MouseHover event on custom usercontrol c#
I created a usercontrol textbox named ucTextBox
contains a label, a textbox and two buttons. 我创建了一个名为ucTextBox
的用户控件文本框, ucTextBox
包含一个标签,一个文本框和两个按钮。 I put it many in my form. 我把它放在我的表格中。
Now I want to attach a MouseHover event on each ucTextBox
, TextBox
and MaskedTextBox
in my form. 现在,我想在表单中的每个ucTextBox
, TextBox
和MaskedTextBox
上附加一个MouseHover事件。
I do this : 我这样做:
public void AttachHoverEvent(Control CTrl)
{
foreach (Control c in CTrl.Controls)
{
if (c is TextBox || c is MaskedTextBox)
{
c.MouseHover += new EventHandler(afficheDictionnaireChamp);
c.MouseLeave += new EventHandler(desafficheDictionnaireChamp);
continue;
}
if (c is ucTextBox)
{
c.MouseHover += new EventHandler(afficheDictionnaireChamp);
c.MouseLeave += new EventHandler(desafficheDictionnaireChamp);
continue;
}
if (c.HasChildren)
{
AttachHoverEvent(c);
}
}
}
Note : I put ucTextBox
in other condition to put a breakpoint and the condition is true. 注意:我将ucTextBox
置于其他条件下以放置断点,且条件为true。
My code works correctly for TextBox
and MaskedTextBox
but don't work on my ucTextBox
(Nothing happen). 我的代码对TextBox
和MaskedTextBox
正常工作,但对ucTextBox
(什么也没有发生)。
I try to add this in my ucTextBox
class : 我尝试将其添加到我的ucTextBox
类中:
private void txbValeur_MouseHover(object sender, EventArgs e)
{
if (this.MouseHover != null)
this.MouseHover(this, e);
}
This my target events function : 这是我的目标事件函数:
public void afficheDictionnaireChamp(object sender, EventArgs e)
{
Dictionnaire dico = new Dictionnaire();
Control snd = (Control)sender;
string table = dico.getNomTable(this.Name, snd.Name);
string champ = dico.getNomChamp(this.Name, snd.Name);
if (table != "" && champ != "")
Globals.FormMain.tslTable.Text = table + " - " + champ;
else
Globals.FormMain.tslTable.Text = "";
}
public void desafficheDictionnaireChamp(object sender, EventArgs e)
{
Globals.FormMain.tslTable.Text = "";
}
If someone got an idea where the problem can from ? 如果有人知道问题出在哪里?
Thanks in advance ! 提前致谢 !
Thomas 托马斯
尝试将您的父控件背景设置为“透明”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.