[英]Can someone help me identify why C# tooltips show when they shouldn't?
I have tool tips running on a C# form and i have a checkbox to disable them showing up.我有在 C# 表单上运行的工具提示,并且我有一个复选框来禁用它们显示。
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
Tool_Tips = false;
}
else
Tool_Tips = true;
}
where Tool_Tips
is a Global public bool.其中
Tool_Tips
是全局公共布尔值。
each time I hover over a button I use the code:每次我 hover 通过一个按钮我使用代码:
private void Edge_Down_B_MouseHover(object sender, EventArgs e)
{
if (Tool_Tips)
{
Tool_Tip(Tool_Help.Edge_Down, Edge_Down_B);
}
}
my problem is that i have 4 buttons out of like 30 that will display a tooltip regardless of the boolean value.我的问题是,无论 boolean 值如何,我都有 30 个按钮中的 4 个按钮将显示工具提示。 If i put a breakpoint in their code it works correctly, but if i remove the breakpoint their tooltip will show up when it shouldnt.
如果我在他们的代码中放置一个断点,它可以正常工作,但是如果我删除断点,他们的工具提示将在它不应该出现的时候出现。 I did clean build of release mode, rebuilt the project and tried debug mode and they continue to show a tooltip when they shouldnt.
我做了发布模式的干净构建,重建了项目并尝试了调试模式,当他们不应该时,他们继续显示工具提示。
I even changed the code of those 4 buttons to look like:我什至将这 4 个按钮的代码更改为:
private void BlackandWhite_B_MouseHover(object sender, EventArgs e)
{
if (Tool_Tips)
{
if (!checkBox1.Checked)
Tool_Tip(Tool_Help.BlackWhite, BlackandWhite_B);
}
}
and they still show up in normal running mode.并且它们仍然以正常运行模式显示。 they won't show up if i place a breakpoint in.
如果我在其中放置断点,它们将不会出现。
Can anyone tell me why?谁能告诉我为什么?
EDIT: if i run my program, it will start with tooltips disabled with the checkbox checked.编辑:如果我运行我的程序,它将从禁用工具提示开始,并选中复选框。 I will uncheck the box and i will see tooltips.
我将取消选中该框,我将看到工具提示。 if i recheck the box to disable the tooltips, the tooltips i have viewed will still show up even though they are disabled.
如果我重新选中该框以禁用工具提示,我查看过的工具提示仍将显示,即使它们已被禁用。
first of all, make sure there aren't any other event handlers attached to those 4 buttons' Click.首先,确保这 4 个按钮的 Click 上没有附加任何其他事件处理程序。
after that try changing your method as:之后尝试将您的方法更改为:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Application.DoEvents();
Tool_Tips = !checkBox1.Checked;
}
the events might had gotten fired before the checkbox have been checked.在选中复选框之前,这些事件可能已被触发。
and if that did not work either, inside your Tool_Tip method write:如果这也不起作用,请在 Tool_Tip 方法中写入:
if (checkbox1.Checked) return;
and if none of those helped, shoot me in the head:D!如果这些都没有帮助,请朝我的头部开枪:D!
before shooting me, do this: in debug mode disable(or delete) all your breakpoints and put one just in your Tool_Tip method's first line.在拍摄我之前,请执行以下操作:在调试模式下禁用(或删除)所有断点并将一个仅放在 Tool_Tip 方法的第一行中。
make the bug show up and your breakpoint be hit.使错误出现并击中您的断点。 then from the debug menu, open Call Stack and check that from where your method has been called.
然后从调试菜单中,打开调用堆栈并检查调用方法的位置。 this might lead you to the problem, because I think you method is being called from an unwanted point of code.
这可能会导致您遇到问题,因为我认为您的方法是从不需要的代码点调用的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.