1

Possible Duplicate:
create custom tooltip C#

Does anyone know of a way to make a box 'popup' when the user cursors over a certain item?

For example, I want to have a PictureBox on a C# forms application and when the user cursors over it, a box of text will pop up.

I'm aware of ToolTip however I was thinking of something more customisable; in my mind I'm thinking of the kind of popup boxes you see in World of WarCraft when you cursor over an item in your inventory (obviously it doesn't have to be THAT flashy, but at least one where the text colour, background colour, text etc. are all modifiable).

Community
  • 1
  • 1
Edward
  • 235
  • 4
  • 18
  • You could use another form to do that, using the show/hide on the mouse over/out actions – Prix Oct 23 '12 at 21:35

3 Answers3

3

You can use a ToolStripControlHost to host a control (for instance a panel) and add the content you want. Then you add that control to a ToolStripDropDown using the Items collection, and use the Show(Control,Point) method to show the control.


Thought I'd add an example

public class Form1 {
    public Form1() {
        ToolStripDropDown customToolTip = new ToolStripDropDown();
        customToolTip.Items.Add(new CustomPopupControl("Hello", "world"));
        MouseMove += (o, e) => {
            Point location = e.Location;
            location.Offset(0, 16);
            customToolTip.Show(this, location);
        };
    }

    class CustomPopupControl : ToolStripControlHost {
        public CustomPopupControl(string title, string message)
            : base(new Panel()) {
            Label titleLabel = new Label();
            titleLabel.BackColor = SystemColors.Control;
            titleLabel.Text = title;
            titleLabel.Dock = DockStyle.Top;

            Label messageLabel = new Label();
            messageLabel.BackColor = SystemColors.ControlLightLight;
            messageLabel.Text = message;
            messageLabel.Dock = DockStyle.Fill;

            Control.MinimumSize = new Size(90, 64);
            Control.Controls.Add(messageLabel);
            Control.Controls.Add(titleLabel);
        }
    }
}
Patrick
  • 17,669
  • 6
  • 70
  • 85
1

I mean if it a button or an image button you can add something like MouseHover action and then show your message

private void button1_MouseHover(object sender, System.EventArgs e) 
{
MessageBox.Show("yourmessage"); 

} 
COLD TOLD
  • 13,513
  • 3
  • 35
  • 52
0

you need to customize the tooltip. refer to http://www.codeproject.com/Articles/98967/A-ToolTip-with-Title-Multiline-Contents-and-Image

There are some other articles there, but this one works fine for me.

You may need to add code for your requirement.

urlreader
  • 6,319
  • 7
  • 57
  • 91