Windows 窗体中的工具提示问题(C#)

发布于 2024-09-28 17:26:23 字数 466 浏览 3 评论 0原文

我有带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

唔猫 2024-10-05 17:26:23

你这样说:

打开表单后,即使我们将鼠标移到控件上,工具提示也不会立即出现。但是一旦我点击表单,工具提示就可以正常工作。

这让我认为这是标准的 Windows 行为,并且当您打开它时您的表单没有获得焦点。许多应用程序中的工具提示仅在其父窗口被激活时才起作用。

You said this:

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.

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.

说不完的你爱 2024-10-05 17:26:23

我希望这有帮助。它解决了我在 form_load 事件上未显示工具提示的问题。
我注意到手动单击 WindowsForm 控件后工具提示起作用了。

由于某种原因,直到您的 WindowsForm 控件处于活动状态(通常是用户单击窗体后),它才会起作用。

因此,要解决此问题,您需要激活代码后面的表单。

this.Activate();

ToolTip toolTip = new ToolTip();
toolTip.ToolTipTitle = "Info";
toolTip.ToolTipIcon = ToolTipIcon.Info;
toolTip.UseFading = true;
toolTip.UseAnimation = true;
toolTip.IsBalloon = true;
toolTip.ShowAlways = true;
toolTip.AutoPopDelay = 5000;
toolTip.InitialDelay = 1000;
toolTip.ReshowDelay = 500;
toolTip.Show("This is button1", button1, 10000);

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.

this.Activate();

ToolTip toolTip = new ToolTip();
toolTip.ToolTipTitle = "Info";
toolTip.ToolTipIcon = ToolTipIcon.Info;
toolTip.UseFading = true;
toolTip.UseAnimation = true;
toolTip.IsBalloon = true;
toolTip.ShowAlways = true;
toolTip.AutoPopDelay = 5000;
toolTip.InitialDelay = 1000;
toolTip.ReshowDelay = 500;
toolTip.Show("This is button1", button1, 10000);
眼趣 2024-10-05 17:26:23

从 form1 的构造函数调用 SetButtonlabels()

call SetButtonlabels() from constructor of form1

一曲琵琶半遮面シ 2024-10-05 17:26:23

在哪个方法中调用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文