// <snippet80> // This event handler is invoked when // the "Apply Renderers" button is clicked. // Depending on the value selected in a ComboBox control, // it applies a custom renderer selectively to // individual MenuStrip or ToolStrip controls, // or it applies a custom renderer to the // application as a whole. void applyButton_Click(object sender, EventArgs e) { ToolStrip ms = ToolStripManager.FindToolStrip("MenuStrip"); ToolStrip ts = ToolStripManager.FindToolStrip("ToolStrip"); if (targetComboBox.SelectedItem != null) { switch (targetComboBox.SelectedItem.ToString()) { case "Reset": { ms.RenderMode = ToolStripRenderMode.ManagerRenderMode; ts.RenderMode = ToolStripRenderMode.ManagerRenderMode; // Set the default RenderMode to Professional. ToolStripManager.RenderMode = ToolStripManagerRenderMode.Professional; break; } case "All": { ms.RenderMode = ToolStripRenderMode.ManagerRenderMode; ts.RenderMode = ToolStripRenderMode.ManagerRenderMode; // Assign the custom renderer at the application level. ToolStripManager.Renderer = new CustomProfessionalRenderer(); break; } case "MenuStrip": { // Assign the custom renderer to the MenuStrip control only. ms.Renderer = new CustomProfessionalRenderer(); break; } case "ToolStrip": { // Assign the custom renderer to the ToolStrip control only. ts.Renderer = new CustomProfessionalRenderer(); break; } } } }
public void BehaviorFindToolStrip() { // Default stuff Assert.AreEqual(null, ToolStripManager.FindToolStrip(string.Empty), "A1"); Assert.AreEqual(null, ToolStripManager.FindToolStrip("MyStrip"), "A2"); ToolStrip ts = new ToolStrip(); ts.Name = "MyStrip"; // Basic operation Assert.AreSame(ts, ToolStripManager.FindToolStrip("MyStrip"), "A3"); // Dispose removes them ts.Dispose(); Assert.AreEqual(null, ToolStripManager.FindToolStrip("MyStrip"), "A4"); ts = new ToolStrip(); ts.Name = "MyStrip1"; MenuStrip ms = new MenuStrip(); ms.Name = "MyStrip2"; // Basic operation Assert.AreSame(ts, ToolStripManager.FindToolStrip("MyStrip1"), "A5"); Assert.AreSame(ms, ToolStripManager.FindToolStrip("MyStrip2"), "A6"); // Find unnamed strip StatusStrip ss = new StatusStrip(); Assert.AreEqual(ss, ToolStripManager.FindToolStrip(string.Empty), "A7"); // Always return first unnamed strip ContextMenuStrip cms = new ContextMenuStrip(); Assert.AreEqual(ss, ToolStripManager.FindToolStrip(string.Empty), "A8"); // Remove first unnamed strip, returns second one ss.Dispose(); Assert.AreEqual(cms, ToolStripManager.FindToolStrip(string.Empty), "A9"); // ContextMenuStrips are included cms.Name = "Context"; Assert.AreEqual(cms, ToolStripManager.FindToolStrip("Context"), "A10"); }