Display image on mouse in window form?

I am working on a project in C # using windows forms. me and the group in which I want to make it so that when the user hovers over the image, in our case the map, that a larger image of this map appears next to the mouse arrow, similar to how the tip tool will work. I don’t think you can use a hint for this, I tried to search everywhere, any advice or examples would be very grateful to you

+6
source share
3 answers

You can see this code draft article .

It shows you how to create an OwnerDrawn tooltip with an image.

+7
source

Thanks for the answers that I understood. What I wanted to do was that when I crossed a certain area, another image for that area would appear just like a tool tip. So after some research, I figured out how to create my own class of prompts.

here is an example.

public partial class Form1 : Form { public Form1() { InitializeComponent(); CustomToolTip tip = new CustomToolTip(); tip.SetToolTip(button1, "text"); tip.SetToolTip(button2, "writing"); button1.Tag = Properties.Resources.pelican; // pull image from the resources file button2.Tag = Properties.Resources.pelican2; } } class CustomToolTip : ToolTip { public CustomToolTip() { this.OwnerDraw = true; this.Popup += new PopupEventHandler(this.OnPopup); this.Draw +=new DrawToolTipEventHandler(this.OnDraw); } private void OnPopup(object sender, PopupEventArgs e) // use this event to set the size of the tool tip { e.ToolTipSize = new Size(600, 1000); } private void OnDraw(object sender, DrawToolTipEventArgs e) // use this to customzie the tool tip { Graphics g = e.Graphics; // to set the tag for each button or object Control parent = e.AssociatedControl; Image pelican = parent.Tag as Image; //create your own custom brush to fill the background with the image TextureBrush b = new TextureBrush(new Bitmap(pelican));// get the image from Tag g.FillRectangle(b, e.Bounds); b.Dispose(); } } 

}

+4
source

A simple way is to hide / show the window with the image in the specified location. Another method is loading and drawing (drawing) an image using the GDI API.

+2
source

Source: https://habr.com/ru/post/902355/


All Articles