工具提示气球显示位置(出错通知) [英] Tooltip baloon display position (for error notification)
问题描述
我问了一段与之前密切相关的问题:
通知用户错误的替代方法
总之,我试图找到一种快速简便的方式来通知用户没有使用弹出窗口的错误。
现在我已经使用工具提示池实现了这一点。问题是,即使我给它一个一般的位置,气泡的小尖锐的部分根据消息的大小改变位置(见附图)。通常情况下,我将使用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);
}
}
这远远超出了要求的范围但是我的老板是个细细的贴子,所以除了解决这个问题,我必须快速解决。我需要一些相对容易实现的东西,不会摇滚当前的软件,我接近释放。当然,我会听任何建议,无论是否可实现。至少我可以学习一些东西。
*编辑:似乎我的形象没有显示。我不知道这只是我的电脑。哦,好吧...
我知道这是一个相当老的问题,我想我几乎错过了你的交付死线4年...但我相信这会解决您遇到的问题:
private void ShowTooltipBalloon(string title,string msg)
{
if(this.InvokeRequired)
{
this.BeginInvoke(new EventHandler(delegate {ShowTooltipBalloon(title,msg);}));
}
else
{
//设计器连接到this.components
//所以也可以这样做...
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;
//将此工具提示绑定到statusStrip控件
//但是不要设置一个值
//因为如果你这样做复制你的图像中的问题
tt.SetToolTip(this.statusStrip1,String.Empty);
// calc x
int x = 0;
foreach(ToolStripItem tbi in this.statusStrip1.Items)
{
//找到工具条项
//工具提示需要指向
if(tbi == this.toolStripDropDownButton1)
{
break;
}
x = x + tbi.Size.Width;
}
// guestimate y
int y = -this.statusStrip1.Size.Height - 50;
//显示它使用statusStrip控件
//作为所有者
tt.Show(msg,this.statusStrip1,x,y,5000);
}
}
I asked a question closely related to this awhile ago: Alternative way to notify the user of an error
In short, i was trying to find a quick and easy way to notify the user of errors without using popups.
Now i have implemented this using tooltip baloons. The problem is that even if i give it a general location, the little pointed part of the bubble changes position depending on the size of the message (see image attached). Normally, I would use SetToolTip() and assign it a control so that it always points to that control. However the control is a label or image in a statusbar.
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);
}
}
This is very much out of the scope of the requirements but my boss is a stickler for details, so in addition to solving this, i have to solve it fast. I need something relatively easy to implement that wont "rock the boat" of the current software which i am close to releasing.
That being said, of course i'll listen to any advice, whether it's implementable or not. At least i might learn something.
*EDIT : It seems my image isn't showing. I don't know if it's just my computer. Oh well...
I know this is a rather old question and I guess I missed your delivery dead-line by almost 4 years...but I believe this fixes the issue you experienced:
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);
}
}
这篇关于工具提示气球显示位置(出错通知)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!