开发者

Tooltip baloon display position (for error notification)

开发者 https://www.devze.com 2023-01-14 08:08 出处:网络
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 po

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 - toolSt开发者_开发百科ripStatusLabel8.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.

Tooltip baloon display position (for error notification)

*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);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消