Windows 窗体中的工具提示问题(C#)
我有带有 4 个按钮和图像的表单。对于所有这些控件,我使用以下代码添加了工具提示,
ToolTip objToolTip=null;
.....
public Form1()
{
objToolTip=new ToolTip();
}
.....
//Used to set the button lables based on Data from database
private void SetButtonlabels()
{
objToolTip.SetToolTip(btnSAPConnect, "Connects to SAP");
}
问题是,打开表单后,即使我们将鼠标移到控件上,工具提示也不会立即出现。但是,一旦我单击表单,工具提示就可以正常工作。我不确定是什么导致了问题。
任何人都可以帮助解决这个问题吗?
I have form with 4 buttons and Image. For all these controls i have added tool tip by using the following code
ToolTip objToolTip=null;
.....
public Form1()
{
objToolTip=new ToolTip();
}
.....
//Used to set the button lables based on Data from database
private void SetButtonlabels()
{
objToolTip.SetToolTip(btnSAPConnect, "Connects to SAP");
}
the problem is, Once the form is opened, the tool tips are not coming immediately even if we move our mouse over the control. But Once i click on the form, then tool tips are working properly. I am not sure which is causing the problem.
Can anybody please help to fix this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你这样说:
这让我认为这是标准的 Windows 行为,并且当您打开它时您的表单没有获得焦点。许多应用程序中的工具提示仅在其父窗口被激活时才起作用。
You said this:
This leads me to think it's standard windows behaviour, and that your form just isn't getting focus when you open it. Tooltips in many apps will only work if their parent window is activated.
我希望这有帮助。它解决了我在 form_load 事件上未显示工具提示的问题。
我注意到手动单击 WindowsForm 控件后工具提示起作用了。
由于某种原因,直到您的 WindowsForm 控件处于活动状态(通常是用户单击窗体后),它才会起作用。
因此,要解决此问题,您需要激活代码后面的表单。
I hope this helps. It solved the problem i had of the tooltip not showing on the form_load event.
I noticed the tooltip working after i manually clicked on my WindowsForm control.
For some reason it won't work until your WindowsForm control is active (Usually once a user clicks on the Form).
So to solve this you will need to activate your Form behind code.
从 form1 的构造函数调用 SetButtonlabels()
call SetButtonlabels() from constructor of form1
在哪个方法中调用 SetButtonlabels()?
尝试在表单初始化后调用它。
In wich method you call SetButtonlabels()?
Try to call it after the initialization of the form.
我刚刚将焦点集中在窗体上的一个控件上。它开始工作了。
I have just set focus on one control on the form. It started working.