The menu and toolbar are essential for WinForm interface layout! However, MenuStrip and ToolStrip cannot directly set the border style. If you want to achieve the separation line between the menu and toolbar, it is not easy to implement it. Today, I checked msdn and found a method, share it with you. If there is a better way, you can post it and make progress together;
First, create a CustomProfessionalRenderer class (the class name can be defined at Will) inherited from ToolStripProfessionalRenderer. The Code is as follows:
/// <Summary>
/// Customize the menu toolbar Style
/// </Summary>
Class CustomProfessionalRenderer: ToolStripProfessionalRenderer
{
// Reload the OnRenderToolStripBorder method of the ToolStripProfessionalRenderer class
Protected override void OnRenderToolStripBorder (ToolStripRenderEventArgs e)
{
Base. OnRenderToolStripBorder (e );
ControlPaint. DrawBorder (
E. Graphics,
E. AffectedBounds,
SystemColors. controlDarkDark, 0, ButtonBorderStyle. none, SystemColors. control, 1, ButtonBorderStyle. inset, SystemColors. controlDarkDark, 0, ButtonBorderStyle. none, SystemColors. controlDark, 0, ButtonBorderStyle. none );
}
}
Then, you can set the Renderer attribute of MenuStrip or ToolStrip to OK. The Code is as follows:
Private void Form1_Load (object sender, EventArgs e)
{
This. toolStrip1.Renderer = new CustomProfessionalRenderer (); // you can specify a custom style.
}
Finally, it should be noted that if you set the MenuStrip border, the effect is not very good, because the border of the sub-menu and the control's main border will be drawn using this style; this will cause repetition, therefore, we recommend that you set the ToolStrip style! The effect is as follows: