/// <summary> /// Sets the toolbar visibility. /// </summary> /// <param name="toolbarName">Name of the toolbar.</param> /// <param name="visible">if set to <c>true</c> [visible].</param> public void SetToolbarVisibility(string toolbarName, bool visible) { ToolStrip strip = GetToolbar(toolbarName); if (strip != null) { ToolbarRegion region = _toolstripRegions[toolbarName]; if (visible) { switch (region) { case ToolbarRegion.Bottom: toolStripContainer.BottomToolStripPanel.Controls.Add(strip); break; case ToolbarRegion.Left: toolStripContainer.LeftToolStripPanel.Controls.Add(strip); break; case ToolbarRegion.Right: toolStripContainer.RightToolStripPanel.Controls.Add(strip); break; case ToolbarRegion.Top: toolStripContainer.TopToolStripPanel.Controls.Add(strip); break; } } else { switch (region) { case ToolbarRegion.Bottom: toolStripContainer.BottomToolStripPanel.Controls.Remove(strip); break; case ToolbarRegion.Left: toolStripContainer.LeftToolStripPanel.Controls.Remove(strip); break; case ToolbarRegion.Right: toolStripContainer.RightToolStripPanel.Controls.Remove(strip); break; case ToolbarRegion.Top: toolStripContainer.TopToolStripPanel.Controls.Remove(strip); break; } } } }
/// <summary> /// Adds the toolbar. /// </summary> /// <param name="name">The name.</param> /// <param name="toolbar">The toolbar.</param> /// <param name="region">The region.</param> /// <param name="canToggleVisibility">if set to <c>true</c> [can toggle visibility].</param> public void AddToolbar(string name, ToolStrip toolbar, ToolbarRegion region, bool canToggleVisibility) { _toolstrips.Add(name, toolbar); _toolstripRegions.Add(name, region); if (canToggleVisibility) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Text = name; item.Tag = name; item.Checked = true; item.CheckOnClick = true; item.Click += delegate { SetToolbarVisibility(name, item.Checked); }; ctxToolbar.Items.Add(item); } switch (region) { case ToolbarRegion.Top: toolStripContainer.TopToolStripPanel.Controls.Add(toolbar); break; case ToolbarRegion.Bottom: toolStripContainer.BottomToolStripPanel.Controls.Add(toolbar); break; case ToolbarRegion.Left: toolStripContainer.LeftToolStripPanel.Controls.Add(toolbar); break; case ToolbarRegion.Right: toolStripContainer.RightToolStripPanel.Controls.Add(toolbar); break; } }