![]() |
| | #1 |
| Registered User Join Date: Oct 2007
Posts: 42
| Custom ToolTip I've created a form to be used as a more informative tooltip, whenever the mouse hovers over a ToolBar Item it should be shown. The problem is, as soon as the tooltip form is shown, the toolbar is closed immediately, and hence the tooltip. how can i prevent from the toolbar to be closed ? |
| khdani is offline | |
| | #2 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| Use a standard ToolTip but override the painting so it can appear as you want it, while still behaving like a normal tool tip. |
| theoobe is offline | |
| | #3 |
| Registered User Join Date: Mar 2009 Location: england
Posts: 76
| I've been having a play with the idea and come up with a little demo to explain what I mean. OK first I made this class which is based on a standard inherited ToolTip: Code: using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class CustomToolTip : ToolTip
{
public CustomToolTip()
{
this.OwnerDraw = true;
this.Popup += new PopupEventHandler(this.OnPopup);
this.Draw += new DrawToolTipEventHandler(this.OnDraw);
}
private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip
{
e.ToolTipSize = new Size(200, 100);
}
private void OnDraw(object sender, DrawToolTipEventArgs e) // use this event to customise the tool tip
{
Graphics g = e.Graphics;
LinearGradientBrush b = new LinearGradientBrush(e.Bounds,
Color.GreenYellow, Color.MintCream, 45f);
g.FillRectangle(b, e.Bounds);
g.DrawRectangle(new Pen(Brushes.Red, 1), new Rectangle(e.Bounds.X, e.Bounds.Y,
e.Bounds.Width - 1, e.Bounds.Height - 1));
g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Silver,
new PointF(e.Bounds.X + 6, e.Bounds.Y + 6)); // shadow layer
g.DrawString(e.ToolTipText, new Font(e.Font, FontStyle.Bold), Brushes.Black,
new PointF(e.Bounds.X + 5, e.Bounds.Y + 5)); // top layer
b.Dispose();
}
}
}
Then for demonstration, create a button on your form and add a Hover event: Code: using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private CustomToolTip tip;
public Form1()
{
InitializeComponent();
this.tip = new CustomToolTip();
}
private void button1_MouseHover(object sender, EventArgs e)
{
this.tip.SetToolTip(this.button1, "this is a test");
}
}
}
Last edited by theoobe; 09-10-2009 at 11:06 AM. |
| theoobe is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Custom Allocation | SevenThunders | C Programming | 17 | 04-09-2007 04:10 PM |
| FindWindowEx() fails with ToolTip class | @nthony | Windows Programming | 3 | 01-16-2007 03:43 AM |
| Stl sets and custom classes. | cunnus88 | C++ Programming | 3 | 05-12-2006 11:58 PM |
| Tooltip won't display over toolbar button | minesweeper | Windows Programming | 5 | 06-20-2003 01:21 AM |
| Tab Controls - API | -KEN- | Windows Programming | 7 | 06-02-2002 09:44 AM |