我正在使用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. 如何在鼠标悬停上显示多个图像php
- 8. 将鼠标悬停在文本上时显示图像
- 9. 在鼠标悬停上显示隐藏图像
- 10. 将鼠标悬停在图像上时显示文字
- 11. 当鼠标悬停在图像上时显示按钮(rails image_tag)
- 12. 在鼠标悬停上显示文字
- 13. 在图像上鼠标悬停时显示超链接和弹出窗口!
- 14. 在其他图像的鼠标悬停上显示特定位置的图像
- 15. 鼠标悬停上的其他图像
- 16. 图像上的鼠标悬停操作
- 17. Javascript。将鼠标悬停在右侧显示图像的图像上。
- 18. 图像悬停 - 鼠标显示为文本图标?
- 19. 悬停图像? (鼠标)
- 20. 在鼠标悬停上显示jQuery弹出窗口
- 21. 在webpart上显示的图像上的鼠标悬停上显示来自Sharepoint库的图像
- 22. 如何显示鼠标悬停/悬停上单元格的值
- 23. 更改鼠标悬停和鼠标悬停在CSS中的图像
- 24. 如何让按钮上的图像在鼠标悬停上显示? WPF
- 25. 从悬停/鼠标悬停的api上旋转图像
- 26. 在鼠标悬停时显示大图像与自动位置
- 27. 图片上鼠标悬停
- 28. Core-Plot Mac:在图中的鼠标悬停点显示标签
- 29. 在Aframe中将鼠标悬停在图像和标题上
- 30. 如何在鼠标悬停(悬停)上显示Google地图控件?
+1 @MarkHall伟大的小费! –