菜单条和工具条r [英] Menu Strip and Toolstrip r
问题描述
大家好
我在使用MenuStrip和ToolStrip的渲染器时遇到了一些问题
I have some problem with Renderer for MenuStrip and ToolStrip
在WinForm中我有一个带有几个ToolStripMenuItems的MenuStrip( "Scelta Colonne","Cerca","Filtra","Raggruppa") ,然后在运行时我将SubItems添加到ToolStrpMenuItems之一("Raggruppa"
In WinForm I have a MenuStrip with several ToolStripMenuItems ("Scelta Colonne", "Cerca", "Filtra", "Raggruppa") , then at runtime I add SubItems to one of the ToolStrpMenuItems ("Raggruppa"
在下面的屏幕截图中)
我使用MyRenderer类来自定义渲染,特别是我使用以下代码
I use a MyRenderer Class to customize rendering and in particular I use the following code to
更改ToolStripBackround颜色(带渐变)
change ToolStripBackround color (with gradient)
Protected Overrides Sub OnRenderToolStripBackground(ByVal e As ToolStripRenderEventArgs)
MyBase.OnRenderToolStripBackground(e)
Dim b As New Drawing2D.LinearGradientBrush(e.AffectedBounds, clrVerBG_GrayBlue, clrVerBG_White,
Drawing2D.LinearGradientMode.Horizontal)
e.Graphics.FillRectangle(b, e.AffectedBounds)
End Sub
每件事都好但是我在"Raggruppa"的SubItem容器中得到了Gradient BackColor。在Form的顶部的MenuStrip中。
Every thing is Ok, but I get the Gradient BackColor both in the SubItem Container of "Raggruppa" and in the MenuStrip on top of Form.
问题是:如何避免在菜单条中更改渐变Backcolor并在Raggruppa SubItems中保持渐变背景色?
The question is: How can I avoid to change the gradient Backcolor in the Menu Strip and maintain the gradient backcolor in the Raggruppa SubItems ?
换句话说,如何区分 MenuStrip中 来自SubItems ToolstripMenuItem容器)
In other words how can I distinguish the MenuStrip from SubItems ToolstripMenuItem Container )
感谢您的帮助
推荐答案
我想你可以设置使用以下代码的渐变。
I think you can set the gradient with the code below.
Imports System.Drawing.Drawing2D
Public Class Form1
Public Class MyRenderer
Inherits ToolStripProfessionalRenderer
Public Sub New()
MyBase.New(New MyColors())
End Sub
End Class
Public Class MyColors
Inherits ProfessionalColorTable
Public Overrides ReadOnly Property MenuStripGradientBegin As Color
Get
Return Color.Blue
End Get
End Property
Public Overrides ReadOnly Property MenuStripGradientEnd As Color
Get
Return Color.Red
End Get
End Property
End Class
Partial Class CustomContrls_MenuStrip
Inherits MenuStrip
Private _themeColor As Color = Color.Gray
Public Property ThemeColor As Color
Get
Return _themeColor
End Get
Set(ByVal value As Color)
_themeColor = value
Me.Renderer = New MyRenderer()
End Set
End Property
End Class
End Class
最好的问候,
Best Regards,
Alex
这篇关于菜单条和工具条r的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!