|
//
// ___ _____ ___ ___ __ __
// / __|_ _/ _ \| _ \ \/ |
// \__ \ | || (_) | / |\/| |
// |___/ |_| \___/|_|_\_| |_|
//
// Storm.TabControl.dll
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Storm.TabControl.dll was created under the LGPL license.
// It was based on another .dll and evolved from that one.
// The original .dll was created by Hadi Eskandari.
//
// What is Storm?
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯
// Storm is a set of dynamic link libraries used in Theodor
// "Vestras" Storm Kristensen's application "Moonlite".
//
//
// Thanks:
// ¯¯¯¯¯¯¯
// - Hadi Eskandari for creating and publishing the library.
//
//
// Copyright (c) Theodor "Vestras" Storm Kristensen 2009
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//
namespace Storm.TabControl
{
using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
/// <summary>
/// Defines the default action of a TabToolStripMenuItem.
/// </summary>
public enum TabDefaultAction
{
/// <summary>
/// When used, the TabToolStripMenuItem will simply close its tab.
/// </summary>
Close = 0,
/// <summary>
/// When used, the TabToolStripMenuItem will close all tabs but itself.
/// </summary>
CloseAllButThis = 1,
/// <summary>
/// When used, the TabToolStripMenuItem will close all tabs.
/// </summary>
CloseAll = 2
}
public class TabToolStripMenuItem
: ToolStripMenuItem
{
#region Members
// Basic members.
private TabStrip tabParent = null;
private TabDefaultAction defaultAction;
private bool useDefaultAction = false;
#endregion
#region Properties
public TabStrip TabParent
{
get { return tabParent; }
set { tabParent = value; }
}
public TabDefaultAction DefaultAction
{
get { return defaultAction; }
set { defaultAction = value; }
}
[DefaultValue(true)]
public bool UseDefaultAction
{
get { return useDefaultAction; }
set { useDefaultAction = value; }
}
#endregion
#region Methods
#region Overrides
protected override void OnClick(EventArgs e)
{
if (useDefaultAction == true)
{
if (defaultAction == TabDefaultAction.Close)
tabParent.RemoveTab(tabParent.SelectedItem);
else if (defaultAction == TabDefaultAction.CloseAllButThis)
{
TabStripItem selectedItem = tabParent.SelectedItem;
TabStripItemCollection items = new TabStripItemCollection();
foreach (TabStripItem item in tabParent.Items)
{
if (item != selectedItem)
items.Add(item);
}
int tabCount = 0;
while (tabCount < items.Count)
{
tabParent.RemoveTab(items[tabCount]);
tabCount++;
}
}
else if (defaultAction == TabDefaultAction.CloseAll)
{
TabStripItemCollection items = new TabStripItemCollection();
foreach (TabStripItem item in tabParent.Items)
items.Add(item);
int tabCount = 0;
while (tabCount < items.Count)
{
tabParent.RemoveTab(items[tabCount]);
tabCount++;
}
}
}
base.OnClick(e);
}
#endregion
#endregion
/// <summary>
/// Initializes the TabToolStripMenuItem.
/// </summary>
public TabToolStripMenuItem(TabStrip parent)
{
if (parent != null)
tabParent = parent;
else
throw new ArgumentNullException("parent");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.