我正在使用Windows窗体在c#中进行项目工作。 我和我所在的小组希望这样做,以便当用户将鼠标悬停在图像上时(在我们的情况下为卡片)时,该卡片的较大图像会出现在鼠标箭头旁边,非常类似于工具提示将工作。 我不认为你可以使用工具提示来做到这一点我已经试过到处寻找, 任何意见或例子将是巨大非常感谢你在windows窗体中的鼠标悬停上显示图像?
6
A
回答
7
你可能想看看这个Code Project Article
它展示了如何创建一个OwnerDrawn工具提示使用的图像。
2
一个简单的方法做的是隐藏/显示图片框在指定的位置。另一种方法是使用GDI
API加载&绘制(绘制)图像。
4
感谢您的回复,我已经弄清楚了一切。 我想要做的是,当我在某个区域上挖掘某个区域的不同图像时,会以与工具提示相同的方式弹出。所以经过一番研究之后,我想出了如何创建我自己的工具提示类。
这里有一个例子。
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();
}
}
}
相关问题
- 1. 显示鼠标悬停的图像
- 2. 将鼠标悬停在另一图像上时显示图像
- 3. 鼠标悬停在图像上时可点击图标显示
- 4. 鼠标悬停在窗体上吗?
- 5. 如何在鼠标悬停在图像中时显示图像?
- 6. 当鼠标悬停在图像上时标签隐藏/显示?
- 7. 如何在悬停我的鼠标的图像上显示悬停效果
- 8. 将鼠标悬停在图像上时显示文字
- 9. AngularJS在鼠标悬停上显示图像
- 10. AJAX鼠标悬停在图像上,显示HTML内容
- 11. 将鼠标悬停在按钮上时显示图像
- 12. 如何在鼠标悬停上显示多个图像php
- 13. 将鼠标悬停在文本上时显示图像
- 14. 当鼠标悬停在链接上时显示图像
- 15. 当鼠标悬停在图像上时显示按钮(rails image_tag)
- 16. 在鼠标悬停上显示文字
- 17. 将鼠标悬停在图像上并在该图像上显示链接
- 18. 当鼠标悬停在图像上时,在图像上显示文字
- 19. 在鼠标悬停上移动图像
- 20. 将鼠标悬停在图像上
- 21. 鼠标悬停在LibreOffice中的文本时显示图像
- 22. 在图像上鼠标悬停时显示超链接和弹出窗口!
- 23. 鼠标悬停的图像模糊图像和显示文字
- 24. 鼠标悬停上的显示框
- 25. 在其他图像的鼠标悬停上显示特定位置的图像
- 26. 图像上的鼠标悬停操作
- 27. 鼠标悬停上的其他图像
- 28. Javascript。将鼠标悬停在右侧显示图像的图像上。
- 29. 使用鼠标悬停在其他div中显示图像
- 30. 图像悬停 - 鼠标显示为文本图标?
+1 @MarkHall伟大的小费! –