The TextOffset property limits the offset to the range (-8, 30): 8 pixels is the default padding of the Text, it's hard-coded in the ToolStripDropDownMenu class, as other parts of the DropDownMenus. To change the position on the MenuItems Text, set a new value to the MenuDesigner.TextOffset Property: ' Move the MenuItems Text 8 pixels to the left ToolStripDesigner = New MenuDesigner(M圜ontextMenuStrip) Private toolStripDesigner As MenuDesigner = Nothing Build a ContextMenuStrip (here named M圜ontextMenuStrip) in the Form Designer, add a private field that references the MenuDesigner and initialize it in the Form constructor, passing the ContextMenuStrip to customize: Public Class SomeForm.→ The same applies to the class that defines the custom Colors. → Of course, any other ProfessonalColorTable derived class can be used instead of the one presented here. The initialization of the MenuDesigner handler also initializes the Renderer and the ColorTable. The MenuDesigner is initialized specifying, in its Constructor, the ToolStrip to customize - a ContextMenuStrip in this case.In the sample code, TextColor (Color of the Items Text) and SelectionColor (Color of the Items when selected) Some of these Colors can be redefined using the MenuDesigner handler. ▶ A sealed (set to NotInheritable in VB.Net) class (here, named MenuRendererColors) with static ( Shared) properties, stores the custom Color definitions, which are then assigned to the different objects and parts described by the ProfessionalColorTable. ▶ A class object derived ProfessionalColorTable (here, named MenuColorTable), which is used to override some or all the default Properties of the Color Table which define the standard Colors of a ToolStrip/MenuStrip, to assign custom colors. The Text offset is set using the MenuDesigner handler's TextOffset Property. In this example (in relation to the question), it overrides OnRenderItemText - to customize the position of the MenuItems Text based on the value of the TextOffset custom property and in relation to the ToolStrip padding - and OnRenderSeparator, which draws the Separator Items, if any, to adjust to the new position of the Items Text. ▶ A class object derived from ToolStripProfessionalRenderer (here, named MenuDesignerRenderer), responsible for the rendering of the Menu Items, overriding (partially or completely) the default behavior. It's the only object that consumers should be allowed to interact with. It also exposes public properties and methods that allow to customize the rendering and the aspect of the MenuItems. ▶ A Handler class (here, named MenuDesigner) which is responsible for the initialization of the other objects (Renderer, ColorTable and Color definitions). It's organized in different objects with different responsibilities: A sample setup that shows how to handle a generic ToolStripProfessionalRenderer and a connected ProfessionalColorTable, used to personalize the rendering and presentation of ToolStrips (MenuStrip, ContextMenuStrip etc.).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |