下面的示例代码接管了 PopupMenu.PaintMenuBar 事件。 事件处理程序使用一个线性渐变画刷填充了菜单的侧栏,并绘制了“XtraBars Suite”文本。
下面的插图显示了使用这个 PopupMenu.PaintMenuBar 事件处理程序的示例。 (注意,相应弹出式菜单的 PopupMenu.MenuBarWidth 属性应该被设置为 20 来得到类似的输出)。
C# | 复制代码 |
---|---|
using System.Drawing; using System.Drawing.Drawing2D; private void popupMenu1_PaintMenuBar(object sender, DevExpress.XtraBars.BarCustomDrawEventArgs e) { // filling the background LinearGradientBrush brush = new LinearGradientBrush(e.Bounds, Color.Black, Color.Blue, LinearGradientMode.Vertical); e.Graphics.FillRectangle(brush, e.Bounds); // formatting the output string StringFormat outStringFormat = new StringFormat(); outStringFormat.Alignment = StringAlignment.Near; outStringFormat.LineAlignment = StringAlignment.Center; outStringFormat.FormatFlags |= StringFormatFlags.DirectionVertical; // transforming the painting surface and modifying the bounding rectangle // this is needed to provide proper string orientation e.Graphics.RotateTransform(180); Rectangle rect = e.Bounds; rect.Offset(-rect.Width, -rect.Height); // painting the string e.Graphics.DrawString("XtraBars Suite", new Font("Tahoma", 11, FontStyle.Bold), new SolidBrush(Color.White), rect, outStringFormat); e.Graphics.ResetTransform(); // prohibiting default painting e.Handled = true; } |
Visual Basic | 复制代码 |
---|---|
Imports System.Drawing Imports System.Drawing.Drawing2D Private Sub PopupMenu1_PaintMenuBar(ByVal sender As Object, _ ByVal e As DevExpress.XtraBars.BarCustomDrawEventArgs) Handles PopupMenu1.PaintMenuBar ' filling the background Dim Brush As New LinearGradientBrush(e.Bounds, Color.Black, Color.Blue, _ LinearGradientMode.Vertical) e.Graphics.FillRectangle(Brush, e.Bounds) ' formatting the output string Dim OutStringFormat As New StringFormat() OutStringFormat.Alignment = StringAlignment.Near OutStringFormat.LineAlignment = StringAlignment.Center OutStringFormat.FormatFlags = OutStringFormat.FormatFlags Or _ StringFormatFlags.DirectionVertical ' transforming the painting surface and modifying the bounding rectangle ' this is needed to provide proper string orientation e.Graphics.RotateTransform(180) Dim Rect As New RectangleF(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height) Rect.Offset(-Rect.Width, -Rect.Height) ' painting the string e.Graphics.DrawString("XtraBars Suite", New Font("Tahoma", 11, FontStyle.Bold), _ New SolidBrush(Color.White), Rect, OutStringFormat) e.Graphics.ResetTransform() ' prohibiting default painting e.Handled = True End Sub |