?
Solved

Tooltip tricks

Posted on 2005-03-01
4
Medium Priority
?
419 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:melodiesoflife
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 13427432
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
0
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 1000 total points
ID: 13427599
Here is sample code to draw circle and change the tooltip when the mouse is on that circle....

==================
using System;
using System.Windows.Forms;
using System.Threading;
using System.Drawing;

class Demo : Form
{      
      private System.Windows.Forms.ToolTip toolTip1;
      private System.ComponentModel.IContainer components;
      public Demo()
      {
            this.components = new System.ComponentModel.Container();      
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            Text = "Testing....";
            BackColor = Color.BlanchedAlmond;
            FormBorderStyle = FormBorderStyle.FixedSingle;
            Cursor = Cursors.Hand;
            StartPosition = FormStartPosition.CenterScreen;
            this.MouseMove += new MouseEventHandler(this.mycircle);
            this.StartPosition = FormStartPosition.CenterScreen;
            this.WindowState = FormWindowState.Maximized;
      }
      
      public static void Main()
      {
          Application.Run(new Demo());
      }
      
      protected override void OnPaint(PaintEventArgs pea)
      {
            System.Drawing.Graphics graphics = this.CreateGraphics();
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(100, 100, 200, 200);
            graphics.DrawEllipse(System.Drawing.Pens.Black, rectangle);
            graphics.DrawRectangle(System.Drawing.Pens.Red, rectangle);            
      }

      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, "Hello This is Windows Application" );
            }
      }
}

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

when tool tip is no circle   MyCircle will be displayed   in remainging places  Hello This is Windows Application  will be displayed
0
 
LVL 6

Author Comment

by:melodiesoflife
ID: 13427754
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
0
 
LVL 14

Expert Comment

by:Thandava Vallepalli
ID: 13427868
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, "" );
          }
     }
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question