Link to home
Start Free TrialLog in
Avatar of melodiesoflife
melodiesoflife

asked on

Tooltip tricks

Hi all.

I have a panel on my form. On the panel, I draw many object like: circle, rectangle, elip ...
I have all information about the co-ordinate of these figures.

Now when I move the mouse over these figure, I want it will show a tooltip, depend on with firgure the mouse over.

Example, when mouse over a circle, tooltip text should be "Circle",
              When mouse over a rectangle, tooltip text should be "rectangle"

Have you got any idea or any link about this?
Avatar of Thandava Vallepalli
Thandava Vallepalli
Flag of United States of America image

You need to store the circle, rectangle co-ordinates to get this functionality.

in form mouse event hadler,  you have to compare the  current mouse coordinates with the  circle or rectanle coordinates. if mouse is in objects, you can re-set the tooltip test....... here is the sample code..... how to reset the tooltip test according to current mouse coordinats..

============================
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace TOOLTIP
{
      /// <summary>
      /// Summary description for Form1.
      /// </summary>
      public class Form1 : System.Windows.Forms.Form
      {
            private System.Windows.Forms.ToolTip toolTip1;
            private System.ComponentModel.IContainer components;

            public Form1()
            {
                  //
                  // Required for Windows Form Designer support
                  //
                  InitializeComponent();

                  //
                  // TODO: Add any constructor code after InitializeComponent call
                  //
            }

            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
                  if( disposing )
                  {
                        if (components != null)
                        {
                              components.Dispose();
                        }
                  }
                  base.Dispose( disposing );
            }

            #region Windows Form Designer generated code
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                  this.components = new System.ComponentModel.Container();
                  this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(292, 273);
                  this.Name = "Form1";
                  this.Text = "Form1";
                  this.toolTip1.SetToolTip(this, "Hello Form");
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_mouse);

            }
            #endregion

            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                  Application.Run(new Form1());
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
            
            }

            private void Form1_mouse(object sender, System.Windows.Forms.MouseEventArgs e)
            {
                  //MessageBox.Show(this, e.X.ToString(), "Show");
                  //MessageBox.Show(this, e.Y.ToString(), "Hi");
                  if( e.X > 200 && e.Y > 200 )
                        this.toolTip1.SetToolTip(this, "Hello You win this game" );
            }

      }
}

==============================

i am changing the tooltip text when mouse x, y co-ordinates are > 200.

itsvtk
ASKER CERTIFIED SOLUTION
Avatar of Thandava Vallepalli
Thandava Vallepalli
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of melodiesoflife
melodiesoflife

ASKER

Thanks  itsvtk

But I hope a real tooltip. I don't want my tooltip display immediately, I want my tooltip display when my mouse over on the figure for a second (hover event).
Any idea
then try this

public void mycircle(object s, MouseEventArgs e)
     {
          if( e.X >= 100 && e.X <= 300 && e.Y >= 100 && e.Y <= 300 )
          {
               toolTip1.SetToolTip( this, "MyCircle" );
          }else
          {
               toolTip1.SetToolTip( this, "" );
          }
     }