如何在一个图片框上使用不同的工具提示文本. [英] How use different tooltip text on one picture box.

查看:94
本文介绍了如何在一个图片框上使用不同的工具提示文本.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,
我正在建立一个窗口窗体,其中可以放置一个图片框..
我想当鼠标进入或将鼠标悬停在图片框上时,根据图像的部分,工具提示文本是不同的..
所以我需要您的帮助才能知道如何将图片分成图片框的不同区域..
在此先感谢

hi friends,
i am building a window Form in which i take the one picture box ..
i want when mouse enter or mouse hover on picture box then tooltip text is diferent on the basis of the portion of image ..
so i need your help to know how to part an image into different region in picture box..
thanks in advance

推荐答案

这有点棘手,但可行.使用Tooltip类有点违反直觉-此类的单个实例可用于多个控件.

基本上,您需要处理事件MouseMove,并在事件参数参数中传递给您的控件的坐标系中使用鼠标指针的坐标.根据此坐标,计算所需的工具提示标题并输出.


对于System.Windows.Forms,它将类似于以下内容:
This is a bit tricky, but doable. Using the Tooltip class is somewhat counter-intuitive — a single instance of this class can be used for several controls.

Basically, you need to handle the event MouseMove and use the coordinate of the mouse pointer in the control''s coordinate system passed to you in the event arguments parameter. Based on this coordinate, calculate desired ToolTip caption and output it.


For System.Windows.Forms, it will look something like this:
ToolTip MyToolTip = //...
PictureBox MyPictureBox = //...

//...

MyPictureBox.MouseMove += delegate(sender, System.Windows.Forms.MouseEventArgs eventArgs) {
    PictureBox pictureBox = (PictureBox)sender;
    MyToolTip.SetToolTip(pictureBox, CalculateTooltipText(eventArgs.X, eventArgs.Y));
};

//where CalculateTooltipText is your semantic method calculating the text depending on mouse coordinates:
string CalculateTooltipText(PictureBox pictureBox, int mouseX, int mouseY) { /*...*/ }



对于C#v.3或v.4,可以更优雅地编写事件处理程序的匿名方法:



For C# v.3 or v.4, the anonymous method for the event handler could be written more elegantly:

MyPictureBox.MouseMove += (sender, eventArgs) => {
    PictureBox pictureBox = (PictureBox)sender;
    MyToolTip.SetToolTip(pictureBox, CalculateTooltipText(eventArgs.X, eventArgs.Y));
};



—SA



—SA


SAKryukov为您提供了答案,请像这样使用它:
SAKryukov provided you with the answer, use it like this:
// This example assumes that the Form_Load event handling method
// is connected to the Load event of the form.
private void Form1_Load(object sender, System.EventArgs e)
{
 // Create the ToolTip and associate with the Form container.
 ToolTip toolTip1 = new ToolTip();

 // Set up the delays for the ToolTip.
 toolTip1.AutoPopDelay = 5000;
 toolTip1.InitialDelay = 1000;
 toolTip1.ReshowDelay = 500;
 // Force the ToolTip text to be displayed whether or not the form is active.
 toolTip1.ShowAlways = true;
            
 // Set up the ToolTip text for the Button and Checkbox.
 toolTip1.SetToolTip(this.button1, "My button1");
 toolTip1.SetToolTip(this.checkBox1, "My checkBox1");
}


请参见工具提示类 [


See ToolTip Class[^] for more information.

Best regards
Espen Harlinn


只需添加,使用图片框会使此操作变得比实际需要的难.图片框的存在是有一个原因的-因此无法编程的人可以轻松地将图片放在表格上.在这里,您真正需要做的是显示自己的图片,并创建相同大小的图像图,并针对不同的工具提示区域使用不同的颜色.然后,当鼠标移动时,您可以跟踪该蒙版图像中所停留的工具提示,并相应地设置工具提示文本.图片框可以缩放您的图像,并使这种代码难以编写.

如果您的区域都是矩形,则可以不使用图像映射而编写代码来检查您所在的矩形.
Just to add, using a picture box makes this harder than it needs to be. A picture box exists for one reason - so people who can''t program can easily put a picture on their form. What you really need to do here, is to show your own picture, and to create an image map that is the same size, and uses different colors for different tooltip areas. Then as the mouse moves, you can track what tooltip you''re over in that mask image, and set the tooltip text accordingly. A picture box can scale your image and make that sort of code harder to write.

If your areas are all rectangles, you can do without the image map and write code to check what rectangle you are in.


这篇关于如何在一个图片框上使用不同的工具提示文本.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆