提示气球显示位置(错误通知) [英] Tooltip baloon display position (for error notification)
问题描述
我问密切相关,这个问题前一段时间:
的 http://stackoverflow.com/questions/2878043/alternative-way-to-notify-the-user-of-an-error
I asked a question closely related to this awhile ago: http://stackoverflow.com/questions/2878043/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.
现在我已经实现这个使用工具提示baloons。问题是,即使我给它一个大致位置,泡沫的小尖头部分取决于消息的大小改变位置(见图片附后)。通常情况下,我会用SetToolTip(),并为其分配一个控件,以便它总是指向控制。然而,控制在一个状态的标签或图像。
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...
推荐答案
我知道这是一个相当古老的问题,我想我错过了你的分娩死线几乎4年......但我相信这个解决您遇到的问题:
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屋!