Каково соглашение со свойством ToolStrip's RenderMode?

Это поддерживается с помощью Reflection http://www.php.net/manual/en/reflectionfunctionabstract.isclosure.php

10
задан Paul Beesley 14 June 2009 в 15:47
поделиться

1 ответ

The RenderMode property allows the developer to precisely control the display of the ToolStrip (or ContextMenu). When you set the RenderMode to ManagerRenderMode, you can create a custom renderer that will allow you to customize the look of the ToolStrip. For example, the code below draws a gray gradient as the background of an the item in a ContextMenu that currently has the mouse over it.

Class CustomProfessionalRenderer
   Inherits ToolStripProfessionalRenderer

   Protected Overrides Sub OnRenderMenuItemBackground(ByVal e As ToolStripItemRenderEventArgs)
      Dim r As Rectangle = e.Item.ContentRectangle

      If e.Item.Selected Then
         Dim b = New LinearGradientBrush(r, Color.FromArgb(255, 227, 224, 215), Color.White, LinearGradientMode.Vertical)
         Try
            e.Graphics.FillRectangle(b, e.Item.ContentRectangle)
         Finally
            b.Dispose()
         End Try
      End If
   End Sub

End Class

Just make sure that in your Form Load event, or some other area that is called before the toolstrip is used, you assign your custom renderer to your toolstrip:

  myToolStrip.Renderer = New CustomProfessionalRenderer()
14
ответ дан 3 December 2019 в 23:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: