473,385 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Add tooltip to a rectangle

2
hello,

I'm trying to figure out how to add a ToolTip to a RectangleF, so when the user moves the mouse over the rectangle a tooltip with information regarding that rectangle will pop up. I hope someone out there knows how to do this. For example this is what I have:

Expand|Select|Wrap|Line Numbers
  1. private void Form1_Paint (object sender, PaintEventArgs e)
  2. {
  3.     Graphics g = e.Graphics;
  4.     RectangleF r = new RectangleF(20.5, 20.3, 100.45, 200.68);
  5.     e.FillRectangle(Brushes.Red, r);
  6.  
  7.     ToolTip myTip = new ToolTip();
  8.     myTip.SetToolTip(r, "This is my Red RectangleF");
  9. }
  10.  
However, this gives an error because RectangleF is not a user control. So, is the best solution to make another class like Rectangle but is a user control, and if so how? Or, is there a component that I could use (like a button)? However, it is important that the control be able to use floats for the location, width, and height, which eliminates the Button control.

Not sure how to do this using floats to designate the SizeF and Location? Hope someone can help.

Thank you,
Joe
May 17 '10 #1
4 11922
GaryTexmo
1,501 Expert 1GB
Try the mouse move event on the form or parent control. If the mouse coordinates intersect the RectangleF object, you can display the tooltip at the cursor on the parent control.
May 17 '10 #2
Plater
7,872 Expert 4TB
Another way would be to use a Control (or some class that inherits from Control...including any of your own classes)
And add it to the tooltip's list with a tooltip. Allowing the tooltip component to do it's thing naturally.
May 17 '10 #3
jbro
2
Thanks Gary,
I'm working through this, but am getting stuck here trying to get the tooltip to show up at the mouse location. I'm using the ToolTip Show() method, which uses the string and a IWin32Window (this is where the problem comes in).

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (r.Contains(e.X, e.Y))
{
ToolTip t1 = new ToolTip();
t1.Show("My Red Rectangle", this);
}
}

Now, I have to have that second parameter in the Show() method, and it has to be an IWin32Window. I thought I could just pass the form in, but that doesn't work. Any ideas? Thank you.
May 17 '10 #4
GaryTexmo
1,501 Expert 1GB
That code should work, it's just that the tool tip won't go away when you leave the rectangle. To that end, you'd need an else condition there to hide the tooltip when it's not intersecting. You could also have a flag to see when you've shown the tooltip or not so you don't keep reshowing it (unless you want it to move with the mouse). I also wouldn't create a new ToolTip object every time. Just create one on the form and use that.

Expand|Select|Wrap|Line Numbers
  1.                 if (m_rect.Contains(e.X, e.Y))
  2.                 {
  3.                     m_tool3.Show("The rectangle!", this, e.X, e.Y);
  4.                 }
  5.                 else
  6.                 {
  7.                     m_tool3.Hide(this);
  8.                 }
That said, Platter's suggestion also sparked me to dive in and try, and that works quite nicely too.

So you've got some options here :D
May 17 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Yves Royer | last post by:
Hi, I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object so i can set some tooltips on checkboxes etc. What...
0
by: Yves Royer | last post by:
Hi, My first post didn't show up so here's a second try. I'm currently writing an application (in VS 2005 bèta 2) and made some own user controls. In each user control I added a ToolTip object...
6
by: ltt19 | last post by:
HI everyone, So, I have many buttons, and all of them must show a tooltip with the same string, except one word, that I must read this owrd from a variable. Although, the "ToolTip on x" property...
0
by: Lucian Wischik | last post by:
I'm using ToolTip.Show(x,y,..) to show my balloon-style tooltip at a specified coordinate. Most of the time it works fine and the "tip" of the balloon points exactly to my specified (x,y)...
2
by: Rich | last post by:
Hello, Some database applicatins have a tooltip feature where when you are dragging the scrollbar of the table view a tooltip appears next to the mouse cursor displaying the approximate record...
5
by: =?Utf-8?B?cGV0ZTE5Njk=?= | last post by:
I use Visual Studio 2005 and created a very simple Form with one button. I added a Tooltip for that button. It shows fine the first time I hover over that button. But if I let it disappear by the...
7
by: The Mad Ape | last post by:
Hi I have code to programatically create a label. It works but when I try to call a sub to create a tooltip it does not work. I do not get an error so have no idea what it wrong. Please review...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
3
omerbutt
by: omerbutt | last post by:
hi there i have downloaded a prototype tooltip from http://www.nickstakenburg.com/projects/prototip/ the logic it uses is to call the script after creating the <div> for example i am using the...
16
by: Charles Law | last post by:
I have to take this personally now. Tooltips have been flakey since the dawn of .NET, but to still have to put up with a disappearing tooltip in VS 2008 is getting beyond a joke. Tooltips have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.