我想创建一个包含以下内容的客户工具提示:
目前我有一个继承自ToolTip Objekt的课程。
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)
{
e.ToolTipSize = new Size(200, 100);
}
private void OnDraw(object sender, DrawToolTipEventArgs e)
{
}
}
但我不知道在“OnDraw-Event”中做什么来显示带有文字的图像。
感谢您的帮助
答案 0 :(得分:2)
查看此http://www.codeproject.com/Articles/42050/ToolTip-With-Image-C 应该充分解释
myImageRectangle = Rectangle.Inflate(myToolTipRectangle, -BORDER_THICKNESS, -BORDER_THICKNESS);
Image toolTipImage = Image.FromFile(filepath);
if (toolTipImage != null)
{
myImageRectangle.Width = 200;
myTextRectangle = new Rectangle(myImageRectangle.Right, myImageRectangle.Top, (myToolTipRectangle.Width - myImageRectangle.Right), myImageRectangle.Height);
myTextRectangle.Location = new Point(myImageRectangle.Right, myImageRectangle.Top);
e.Graphics.FillRectangle(myBackColorBrush, myTextRectangle);
e.Graphics.DrawImage(toolTipImage, myImageRectangle);
e.Graphics.DrawString(e.ToolTipText, myFont,
myTextBrush, myTextRectangle, myTextFormat);
}
答案 1 :(得分:1)
请尝试GDI+
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Image img = Image.FromFile("C:\filepath\filename.jpg");
e.Graphics.DrawImage(img, 0, 0);
var YourTipTextPoint = new Point(0,0);
e.Graphics.DrawString("Hello World", SystemFonts.DefaultFont, Brushes.Black, YourTipTextPoint);
}