【发布时间】:2013-07-07 12:45:13
【问题描述】:
我正在尝试使用 FillPath 在我自己的自定义控件中覆盖标签的 OnPaint 方法。
这是我的控件代码:
public partial class GlassLabel : Label
{
public GlassLabel()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = this.CreateGraphics();
GraphicsPath path = new GraphicsPath();
SolidBrush br = new SolidBrush(Color.Black);
path.AddString("LLOOOOLL", new FontFamily("Microsoft Sans Serif"), (int)FontStyle.Regular, 12, new Point(55, 55), StringFormat.GenericDefault);
g.SmoothingMode = SmoothingMode.HighQuality;
g.FillPath(br, path);
}
}
当我运行它时,标签的文本是一样的,它不使用 FillPath 绘制。
我试图覆盖标签的原因是我想在需要 FillPath 的 Aero 玻璃上使用它。如果我可以将图形(FillPath)转换为一个对象,以便我可以将事件附加到它,我也想知道这方面的信息。
谢谢。
刚试过:
e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
e.Graphics.FillPath(br, path);
没用。
【问题讨论】:
-
尝试使用 PaintEventArgs "e" 中的 Graphics 对象。
-
放置一个断点并验证您的代码是否正在运行。还可以尝试删除对 base.OnPaint 的调用,作为临时测试。
-
它达到了断点,但什么也没有。我已经删除了 base.OnPaint 它使标签根本不绘制。
-
传统的 Winforms 文本绘图不能很好地支持这一点。最好的办法是 pinvoke DrawThemeTextEx() 这样您就可以使用 DTTSOPTS.iGlowSize 创建乳白色背景。将浏览器对准 google 以查找这些关键字的匹配结果。
标签: c# custom-controls label system.drawing