问题描述
我从不完全了解此属性的用途.我可以看到它明显改变了工具栏的设计,并且我发现在Windows XP上将其设置为System使其更适合WinForms样式.
I never quite understood what this property was designed for. I can see that it visibly changes the design of the toolstrip and I find that setting it to System on Windows XP makes it fit much better with the WinForms style.
这里还有更深层的含义吗?呈现控件的方式是否会根本改变,您建议使用哪种模式?
Is there some deeper meaning here? Does the way in which the control is rendered change at all and which mode would you recommend using?
谢谢.
推荐答案
RenderMode属性允许开发人员精确控制ToolStrip(或ContextMenu)的显示.将RenderMode设置为ManagerRenderMode时,可以创建一个自定义渲染器,该渲染器将允许您自定义ToolStrip的外观.例如,下面的代码绘制一个灰色渐变作为ContextMenu中当前将鼠标悬停在其上的项目的背景.
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
只需确保在Form Load事件或使用工具栏之前调用的其他区域中,将自定义渲染器分配给工具栏:
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()
这篇关于ToolStrip的RenderMode属性如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!