-3

I have a class that draws images. (This works fine) I want a toolTip to be displayed when the user hover over the image with the mouse.

In the class's I have:

public Graphics Graphic { get; set; } //Element to draw on

SomeMethod()
{
    Symbol = new Bitmap("C:/Test.JPG");
    Position = new Point(100, 300);

    Graphic.DrawImage(Symbol, Position);
    //Here I want to somehow add the ToolTip to the image
}

There are lot of examples on how to add the ToolTip to a Control but the Image (as I can see it) is not a control and therefore gives an error when I try to.

Am I not looking at the correct path to be adding tooltips to an image or is the Tooltip class not designed to do this?

Mobz
  • 344
  • 1
  • 16
  • You may find this question similar to what you are looking for : https://stackoverflow.com/questions/4295372/how-do-i-add-a-mouse-over-tooltip-to-an-image-using-drawimage – Shai Aharoni Jan 20 '19 at 11:43
  • I'ld prefer `SomeMethod(Graphics Graphic)`: you really need to avoid to store a Graphics object in any way. You are drawing on the surface of a control in any case. You could store a reference of the control you're using as canvas and subscribe to its `MouseMove` event. Then check whether the mouse pointer is inside the Rectangle described by your Images and, if it is, display a ToolTip related to the current Image. You just need to have means to relate an Image to a Rectangle. Welll, you already have location and Bitmap size. Otherwise, build a User/Custom Control (probably better). – Jimi Jan 20 '19 at 11:55

1 Answers1

0

Don't think tooltip is supported in your case, you either have two options

Use a Control like Label and put image in that (this link)

or implement your own tooltip based on mouse events(this link should give you the idea)

hessam hedieh
  • 780
  • 5
  • 18