我正在尝试使用我找到的DrawThemeTextEx类在.NET StatusStrip中绘制航空风格的发光文本。这是我当前的代码,我用它作为StatusStrip的渲染器:
Class GlassStatusRenderer
Inherits System.Windows.Forms.ToolStripProfessionalRenderer
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
e.Graphics.Clear(Color.Transparent)
End Sub
Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
e.Graphics.Clear(Color.Transparent)
Dim glowingText As New GlassText
glowingText.DrawTextOnGlass(Form1.Handle, e.Text, e.TextFont, New Rectangle(e.TextRectangle.Left, e.ToolStrip.Top - 10, e.TextRectangle.Width, e.TextRectangle.Height), 6)
End Sub
结束班
问题是,发光文本似乎是在StatusStrip下面绘制的。有关如何在上绘制状态条带的任何想法吗?
编辑:是否有可能以某种方式将其包装在继承ToolStripStatusLabel的类中?我试过但没有走得太远。
答案 0 :(得分:0)
我不知道StatusStrip,但您可以使用继承System.Windows.Forms.StatusBar或System.Windows.Forms.Control的类,并覆盖OnPaint事件以绘制发光文本。这是一个例子:
public class ctlStatusBar:Control { protected override void OnHandleCreated(EventArgs e) { SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw,true); base.OnHandleCreated(E); }
protected override void OnPaint(PaintEventArgs e)
{
DrawStatusBar(e.Graphics);
}
private void DrawStatusBar(Graphics g)
{
if (Width < 1 || Height < 1) return;
IntPtr primaryHdc = g.GetHdc();
IntPtr memoryHdc = Global.CreateCompatibleDC(primaryHdc);
DrawGlowingText(primaryHdc, memoryHdc, new Rectangle(0, 0, Width, Height), RebarRenderer, p_Text);
}
}