【问题标题】:Tooltip on form load表单加载工具提示
【发布时间】:2013-02-28 17:41:32
【问题描述】:

我有一个登录表单。该表单有 2 个文本框和 3 个按钮。一个按钮显示“学生”。

我想要做的是在表单打开时在此按钮上显示一个工具提示。我不想必须转到按钮并将鼠标悬停在其上才能显示。我希望表单加载,显示工具提示,然后工具提示应在 5 秒后消失。这是我迄今为止尝试过的:

private void Form1_Load(object sender, EventArgs e)
        {
            toolTip.IsBalloon = true;
            toolTip.ToolTipIcon = ToolTipIcon.Info;
            toolTip.ShowAlways = true;
            toolTip.UseFading = true;
            toolTip.UseAnimation = true;
            toolTip.ToolTipTitle = "Student Mode";
            toolTip.Show("You don't have to log in if you are a student. Just click here to go to the questions.", btnStudent);
        }

【问题讨论】:

  • 您可以在表单加载时启动计时器。将计时器滴答设置为 5000,在第一个滴答事件中停止计时器并将您的工具提示设置为正常的工具提示。

标签: c# winforms tooltip


【解决方案1】:

表单的 Load 事件经常被误用。正是在这里,事件触发之前窗口变得可见。因此,您的工具提示也不可见。

将您的代码移至 Shown 事件处理程序。顺便说一句,支持重写 OnShown(),让一个类监听它自己的事件是没有意义的。

   protected override void OnShown(EventArgs e) {
        base.OnShown(e);
        // Your code here
        //...
   }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 2015-10-12
    • 1970-01-01
    相关资源
    最近更新 更多