工具提示气球显示位置(错误通知)

问题描述:

我问密切相关,这一段时间前一个问题: Alternative way to notify the user of an error工具提示气球显示位置(错误通知)

总之,我试图找到一个快速简便的方法来通知错误的用户,而无需使用弹出窗口。

现在我已经实现了这个使用工具提示baloons。问题是,即使我给它一个大概的位置,气泡的小尖端部分根据消息的大小改变位置(见附图)。通常,我会使用SetToolTip()并为其分配一个控件,以便它始终指向该控件。但是,该控件是状态栏中的标签或图像。

private void ShowTooltipBalloon(string title, string msg) 
{ 
    if (this.InvokeRequired) 
    { 
     this.BeginInvoke(new EventHandler(delegate { ShowTooltipBalloon(title,msg); })); 
    } 
    else 
    { 
     ToolTip tt = new ToolTip(); 
     tt.IsBalloon = true; 
     tt.ToolTipIcon = ToolTipIcon.Warning; 
     tt.ShowAlways = true; 
     tt.BackColor = Color.FromArgb(0xFF, 0xFF, 0x90); 
     tt.ToolTipTitle = title; 

     int x = this.Width - lblLeftTarget.Width - lblVersion.Width - toolStripStatusLabel8.Width - 10; 
     int y = this.Height - lblLeftConnectImg.Height - 60; 
     tt.Show(msg, this, x, y, 5000); 
    } 
} 

这是很离谱的要求范围,但我的老板是细节上的坚持己见,所以除了解决这一点,我必须解决它快。我需要一些相对容易实现的东西,它不会让目前正在发布的软件“摇摆”。

这就是说,当然我会听任何建议,不管它是否可以实施。至少我可能会学到一些东西。 alt text

*编辑:看来我的图像没有显示。我不知道这是不是我的电脑。哦...

+1

如果不创建自己的工具提示窗体,则需要控制线条长度(即在50个字符后使用Environment.NewLine)以确保标准宽度。 – 2011-10-11 14:17:05

我知道这是一个相当古老的问题,我想我错过了你的分娩死线近4年... ...但我相信这能解决您遇到的问题:

private void ShowTooltipBalloon(string title, string msg) 
{ 
    if (this.InvokeRequired) 
    { 
     this.BeginInvoke(new EventHandler(delegate { ShowTooltipBalloon(title, msg); })); 
    } 
    else 
    { 
     // the designer hooks up to this.components 
     // so lets do that as well... 
     ToolTip tt = new ToolTip(this.components); 

     tt.IsBalloon = true; 
     tt.ToolTipIcon = ToolTipIcon.Warning; 
     tt.ShowAlways = true; 
     tt.BackColor = Color.FromArgb(0xFF, 0xFF, 0x90); 
     tt.ToolTipTitle = title; 

     // Hookup this tooltip to the statusStrip control 
     // but DON'T set a value 
     // because if you do it replicates the problem in your image 
     tt.SetToolTip(this.statusStrip1, String.Empty); 

     // calc x 
     int x = 0; 
     foreach (ToolStripItem tbi in this.statusStrip1.Items) 
     { 
      // find the toolstrip item 
      // that the tooltip needs to point to 
      if (tbi == this.toolStripDropDownButton1) 
      { 
       break; 
      } 
      x = x + tbi.Size.Width; 
     } 

     // guestimate y 
     int y = -this.statusStrip1.Size.Height - 50; 
     // show it using the statusStrip control 
     // as owner 
     tt.Show(msg, this.statusStrip1, x, y, 5000); 
    } 
}