[英]display image on mouseover in windows form?
我正在使用Windows窗體在c#中開發一個項目。 我和我所在的小組想要這樣做,以便當用戶將鼠標懸停在圖像上時(在我們的例子中是一張卡片),該卡片的較大圖像會出現在鼠標箭頭旁邊,就像工具一樣小費會奏效。 我不認為你可以使用工具提示做到這一點我嘗試到處尋找,任何建議或例子都會非常非常感謝你
您可能需要查看此代碼項目文章
它向您展示了如何使用Image創建OwnerDrawn工具提示。
感謝您的反應,我得到了一切。 我想要做的是,當我在某個區域上進行鼠標移動時,該區域的不同圖像將以與工具提示相同的方式彈出。 經過一些研究后,我想出了如何創建自己的工具提示類。
這是一個例子。
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();
}
}
}
一種簡單的方法是隱藏/顯示指定位置的圖片框。 另一種方法是使用GDI
API加載和繪制(繪制)圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.