#if FRAMEWORK20
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
[ToolboxItem(true)]
[DefaultEvent("SelectedTabChanged")]
[Designer("DevComponents.DotNetBar.Design.SuperTabControlDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class SuperTabControl : Control, ISupportInitialize
{
#region Events
///
/// Occurs when a tab is added to the Tabs collection
///
[Description("Occurs when a tab is added to the Tabs collection.")]
public event EventHandler TabItemOpen;
///
/// Occurs when a tab is about to Close
///
[Description("Occurs when a tab is about to Close.")]
public event EventHandler TabItemClose;
///
/// Occurs when a tab is removed from the Tabs collection
///
[Description("Occurs when a tab is removed from the Tabs collection.")]
public event EventHandler TabRemoved;
///
/// Occurs when a tab is about to be displayed
///
[Description("Occurs when a tab is about to be displayed.")]
public event EventHandler BeforeTabDisplay;
///
/// Occurs when a tab is being moved or dragged by the user
///
[Description("Occurs when a tab is being moved or dragged by the user.")]
public event EventHandler TabMoving;
///
/// Occurs when a tab has been moved or dragged by the user
///
[Description("Occurs when a tab has been moved or dragged by the user.")]
public event EventHandler TabMoved;
///
/// Occurs when the Selected tab is changing
///
[Description("Occurs when the Selected tab is changing.")]
public event EventHandler SelectedTabChanging;
///
/// Occurs when the Selected tab has changed
///
[Description("Occurs when the Selected tab has changed.")]
public event EventHandler SelectedTabChanged;
///
/// Occurs when the control needs a tab's bordering path
///
[Description("Occurs when the control needs a tab's bordering path.")]
public event EventHandler GetTabItemPath;
///
/// Occurs when the control needs a tab's Content Rectangle
///
[Description("Occurs when the control needs a tab's Content Rectangle.")]
public event EventHandler GetTabItemContentRectangle;
///
/// Occurs when the control needs to measure a tab
///
[Description("Occurs when the control needs to measure a tab.")]
public event EventHandler MeasureTabItem;
///
/// Occurs before any tab rendering is done
///
[Description("Occurs before any tab rendering is done.")]
public event EventHandler PreRenderTabItem;
///
/// Occurs After all tab rendering is complete
///
[Description("Occurs After all tab rendering is complete.")]
public event EventHandler PostRenderTabItem;
///
/// Occurs when the control needs to get the tab's Text Bounds
///
[Description("Occurs when the control needs to get the tab's Text Bounds.")]
public event EventHandler GetTabTextBounds;
///
/// Occurs when the control needs to get the tab's Image Bounds
///
[Description("Occurs when the control needs to get the tab's Image Bounds.")]
public event EventHandler GetTabImageBounds;
///
/// Occurs when the control needs to get the tab's Close Button Bounds
///
[Description("Occurs when the control needs to get the tab's Close Button Bounds.")]
public event EventHandler GetTabCloseBounds;
///
/// Occurs when the TabStrip background needs painted
///
[Description("Occurs when the TabStrip background needs painted.")]
public event EventHandler TabStripPaintBackground;
///
/// Occurs when a TabStrip MouseUp event is raised
///
[Description("Occurs when a TabStrip MouseUp event is raised.")]
public event EventHandler TabStripMouseUp;
///
/// Occurs when a TabStrip MouseDown event is raised
///
[Description("Occurs when a TabStrip MouseDown event is raised.")]
public event EventHandler TabStripMouseDown;
///
/// Occurs when a TabStrip MouseMove event is raised
///
[Description("Occurs when a TabStrip MouseMove event is raised.")]
public event EventHandler TabStripMouseMove;
///
/// Occurs when a TabStrip MouseClick event is raised
///
[Description("Occurs when a TabStrip MouseClick event is raised.")]
public event EventHandler TabStripMouseClick;
///
/// Occurs when a TabStrip MouseDoubleClick event is raised
///
[Description("Occurs when a TabStrip MouseDoubleClick event is raised.")]
public event EventHandler TabStripMouseDoubleClick;
///
/// Occurs when a TabStrip MouseEnter event is raised
///
[Description("Occurs when a TabStrip MouseEnter event is raised.")]
public event EventHandler TabStripMouseEnter;
///
/// Occurs when a TabStrip MouseHover event is raised
///
[Description("Occurs when a TabStrip MouseHover event is raised.")]
public event EventHandler TabStripMouseHover;
///
/// Occurs when a TabStrip MouseLeave event is raised
///
[Description("Occurs when a TabStrip MouseLeave event is raised.")]
public event EventHandler TabStripMouseLeave;
#endregion
#region Private variables
private readonly SuperTabStrip _TabStrip;
private bool _Initializing;
private bool _TabsVisible = true;
private int _LoadSelectedTabIndex = -1;
#endregion
///
/// Constructor
///
public SuperTabControl()
{
_TabStrip = new SuperTabStrip();
Controls.Add(_TabStrip);
_TabStrip.Dock = DockStyle.Top;
_TabStrip.AutoSelectAttachedControl = true;
_TabStrip.SendToBack();
HookEvents(true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
StyleManager.Register(this);
}
#region Public properties
#region TabStripTabStop
///
/// Gets or sets whether TabStrip will get focus when Tab key is used. Default value is false.
///
[DefaultValue(true), Category("Behavior"), Description("Gets or sets whether TabStrip will get focus when Tab key is used.")]
public bool TabStripTabStop
{
get { return TabStrip.TabStop; }
set { TabStrip.TabStop = value; }
}
protected override void OnGotFocus(EventArgs e)
{
if (TabStripTabStop)
TabStrip.Focus();
base.OnGotFocus(e);
}
#endregion
#region AntiAlias
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Gets or sets whether anti-aliasing is used while painting.")]
public bool AntiAlias
{
get { return (_TabStrip.AntiAlias); }
set { _TabStrip.AntiAlias = value; }
}
#endregion
#region CloseButton properties
#region AutoCloseTabs
///
/// Gets or sets whether tabs are automatically closed when a close button is clicked
///
[Browsable(true), DefaultValue(true), Category("Close Button")]
[Description("Indicates whether tab is automatically closed when close button is clicked.")]
public bool AutoCloseTabs
{
get { return (_TabStrip.AutoCloseTabs); }
set { _TabStrip.AutoCloseTabs = value; }
}
#endregion
#region CloseButtonOnTabsAlwaysDisplayed
///
/// Gets or sets whether the tab's visible close button is displayed for every tab state
///
[Browsable(true), DefaultValue(true), DevCoBrowsable(true), Category("Close Button")]
[Description("Indicates whether the tab's visible close button is displayed for every tab state.")]
public bool CloseButtonOnTabsAlwaysDisplayed
{
get { return (_TabStrip.CloseButtonOnTabsAlwaysDisplayed); }
set { _TabStrip.CloseButtonOnTabsAlwaysDisplayed = value; }
}
#endregion
#region CloseButtonOnTabsVisible
///
/// Gets or sets whether close button is visible on each tab
///
[Browsable(true), DefaultValue(false), DevCoBrowsable(true), Category("Close Button")]
[Description("Indicates whether close button is visible on each tab.")]
public bool CloseButtonOnTabsVisible
{
get { return (_TabStrip.CloseButtonOnTabsVisible); }
set { _TabStrip.CloseButtonOnTabsVisible = value; }
}
#endregion
#region CloseButtonPosition
///
/// Gets or sets the position of the tab close button
///
[Browsable(true), DefaultValue(eTabCloseButtonPosition.Right), DevCoBrowsable(true)]
[Category("Close Button"), Description("Indicates the position of the tab close button.")]
public eTabCloseButtonPosition CloseButtonPosition
{
get { return (_TabStrip.CloseButtonPosition); }
set { _TabStrip.CloseButtonPosition = value; }
}
#endregion
#region TabCloseButtonNormal
///
/// Gets or sets the custom tab Close button image
///
[Browsable(true), DefaultValue(null), Category("Close Button")]
[Description("Indicates the custom tab Close button image.")]
public Image TabCloseButtonNormal
{
get { return (_TabStrip.TabCloseButtonNormal); }
set { _TabStrip.TabCloseButtonNormal = value; }
}
#endregion
#region TabCloseButtonHot
///
/// Gets or sets the custom Close button image that is used on tabs when the mouse is over the close button
///
[Browsable(true), DefaultValue(null), Category("Close Button")]
[Description("Indicates custom Close button image that is used on tabs when the mouse is over the close button.")]
public Image TabCloseButtonHot
{
get { return (_TabStrip.TabCloseButtonHot); }
set { _TabStrip.TabCloseButtonHot = value; }
}
#endregion
#region TabCloseButtonPressed
///
/// Gets or sets the custom Close button image that is used on tabs when the button has been pressed
///
[Browsable(true), DefaultValue(null), Category("Close Button")]
[Description("Indicates custom Close button image that is used on tabs when the button has been pressed.")]
public Image TabCloseButtonPressed
{
get { return (_TabStrip.TabCloseButtonPressed); }
set { _TabStrip.TabCloseButtonPressed = value; }
}
#endregion
#endregion
#region ControlBox
///
/// Gets the TabStrip ControlBox
///
[Browsable(true), Category("Appearance")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("Gets the TabStrip ControlBox.")]
public SuperTabControlBox ControlBox
{
get { return (_TabStrip.ControlBox); }
}
#endregion
#region DisplaySelectedTextOnly
///
/// Gets or sets whether the only Text displayed is for the SelectedTab
///
[Browsable(true), DevCoBrowsable(true), Category("Behavior"), DefaultValue(false)]
[Description("Specifies whether the only Text displayed is for the SelectedTab.")]
public bool DisplaySelectedTextOnly
{
get { return (_TabStrip.DisplaySelectedTextOnly); }
set { _TabStrip.DisplaySelectedTextOnly = value; }
}
#endregion
#region HorizontalText
///
/// Gets or sets whether text is drawn horizontally regardless of tab orientation
///
[Browsable(true), DefaultValue(true), Category("Appearance")]
[Description("Indicates whether text is drawn horizontally regardless of tab orientation.")]
public bool HorizontalText
{
get { return (_TabStrip.HorizontalText); }
set { _TabStrip.HorizontalText = value; }
}
#endregion
#region ImageAlignment
///
/// Gets or sets the default alignment of the Image within the tab
///
[DefaultValue(ImageAlignment.NotSet), Category("Appearance")]
[Description("Indicates the default alignment of the Image within the tab.")]
public ImageAlignment ImageAlignment
{
get { return (_TabStrip.ImageAlignment); }
set { _TabStrip.ImageAlignment = value; }
}
#endregion
#region ImageList
///
/// Gets or sets the ImageList used by the TabStrip and its tab items
///
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the ImageList used by the TabStrip and its tab items.")]
public ImageList ImageList
{
get { return (_TabStrip.ImageList); }
set { _TabStrip.ImageList = value; }
}
#endregion
#region ItemPadding
///
/// Gets or sets BaseItem tab padding in pixels.
///
[Browsable(true), Category("Layout")]
[Description("Indicates BaseItem tab padding in pixels.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Padding ItemPadding
{
get { return (_TabStrip.ItemPadding); }
set { _TabStrip.ItemPadding = value; }
}
#endregion
#region RotateVerticalText
///
/// Gets or sets whether vertical tab text is rotated 180 degrees
///
[Browsable(true), DefaultValue(false), Category("Layout")]
[Description("Indicates whether vertical tab text is rotated 180 degrees.")]
public bool RotateVerticalText
{
get { return (_TabStrip.RotateVerticalText); }
set { _TabStrip.RotateVerticalText = value; }
}
#endregion
#region SelectedPanel
///
/// Gets or sets the SelectedTab based upon the given panel
///
[Browsable(false), DevCoBrowsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SuperTabControlPanel SelectedPanel
{
get
{
if (_TabStrip.SelectedTab != null)
return (_TabStrip.SelectedTab.AttachedControl as SuperTabControlPanel);
return (null);
}
set
{
if (value != null && Controls.Contains(value))
{
if (value.TabItem != null && Tabs.Contains(value.TabItem))
_TabStrip.SelectedTab = value.TabItem;
}
}
}
#endregion
#region ShowFocusRectangle
///
/// Gets or sets whether a focus rectangle is displayed when tab has input focus
///
[Browsable(true), DefaultValue(false), Category("Behavior")]
[Description("Indicates whether a focus rectangle is displayed when tab has input focus.")]
public bool ShowFocusRectangle
{
get { return (_TabStrip.ShowFocusRectangle); }
set { _TabStrip.ShowFocusRectangle = value; }
}
#endregion
#region Tab properties
#region FixedTabSize
///
/// Gets or sets the fixed tab size in pixels. Either Height, Width, or both can be set
///
[Browsable(true), Category("Appearance")]
[Description("Indicates the fixed tab size in pixels. Either Height, Width, or both can be set.")]
public Size FixedTabSize
{
get { return (_TabStrip.FixedTabSize); }
set { _TabStrip.FixedTabSize = value; }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeFixedTabSize()
{
return (_TabStrip.ShouldSerializeFixedTabSize());
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetFixedTabSize()
{
TypeDescriptor.GetProperties(this)["FixedTabSize"].SetValue(this, Size.Empty);
}
#endregion
#region IsTabDragging
///
/// Gets or sets whether a tab is currently in a drag operation
///
[Browsable(false)]
public bool IsTabDragging
{
get { return (_TabStrip.IsTabDragging); }
}
#endregion
#region ReorderTabsEnabled
///
/// Gets or sets whether tabs can be reordered through the user interface
///
[Browsable(true), DevCoBrowsable(true), Category("Behavior")]
[Description("Indicates whether the control tabs can be reordered through the user interface.")]
public bool ReorderTabsEnabled
{
get { return (_TabStrip.ReorderTabsEnabled); }
set { _TabStrip.ReorderTabsEnabled = value; }
}
#endregion
#region SelectedTab
///
/// Gets or sets the selected tab
///
[Browsable(false), DevCoBrowsable(false), Category("Behavior")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SuperTabItem SelectedTab
{
get { return (_TabStrip.SelectedTab); }
set { _TabStrip.SelectedTab = value; }
}
#endregion
#region SelectedTabFont
///
/// Gets or sets the selected tab Font
///
[Browsable(true), DevCoBrowsable(true), Localizable(true), Category("Style"), DefaultValue(null)]
[Description("Indicates the selected tab Font")]
public Font SelectedTabFont
{
get { return (_TabStrip.SelectedTabFont); }
set { _TabStrip.SelectedTabFont = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSelectedTabFont()
{
return (_TabStrip.ShouldSerializeSelectedTabFont());
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSelectedTabFont()
{
_TabStrip.ResetSelectedTabFont();
}
#endregion
#region SelectedTabIndex
///
/// Gets or sets the index of the selected tab
///
[Browsable(true), DevCoBrowsable(true), Category("Behavior")]
[Description("Indicates the index of the selected tab.")]
public int SelectedTabIndex
{
get { return (_TabStrip.SelectedTabIndex); }
set
{
if (_Initializing == true)
_LoadSelectedTabIndex = value;
else
_TabStrip.SelectedTabIndex = value;
}
}
#endregion
#region TabAlignment
///
/// Gets or sets the tab alignment within the Tab-Strip control
///
[Browsable(true), DefaultValue(eTabStripAlignment.Top), DevCoBrowsable(true)]
[Category("Appearance"), Description("Indicates the tab alignment within the Tab-Strip control.")]
public eTabStripAlignment TabAlignment
{
get { return (_TabStrip.TabAlignment); }
set
{
if (_TabStrip.TabAlignment != value)
{
_TabStrip.TabAlignment = value;
SetTabDocking(value);
}
}
}
#region SetTabDocking
///
/// Sets the tab docking based upon the given alignment
///
///
private void SetTabDocking(eTabStripAlignment value)
{
_TabStrip.SuspendLayout();
try
{
switch (value)
{
case eTabStripAlignment.Top:
_TabStrip.Dock = DockStyle.Top;
break;
case eTabStripAlignment.Bottom:
_TabStrip.Dock = DockStyle.Bottom;
break;
case eTabStripAlignment.Left:
_TabStrip.Dock = DockStyle.Left;
break;
case eTabStripAlignment.Right:
_TabStrip.Dock = DockStyle.Right;
break;
}
_TabStrip.SendToBack();
}
finally
{
_TabStrip.ResumeLayout(true);
}
RefreshPanelsStyle();
RecalcLayout();
}
#endregion
#endregion
#region TabFont
///
/// Gets or sets the tab Font
///
[Browsable(true), DevCoBrowsable(true), Localizable(true), Category("Style"), DefaultValue(null)]
[Description("Indicates the tab Font")]
public Font TabFont
{
get { return (_TabStrip.TabFont); }
set { _TabStrip.TabFont = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTabFont()
{
return (_TabStrip.ShouldSerializeTabFont());
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTabFont()
{
_TabStrip.ResetTabFont();
}
#endregion
#region TabHorizontalSpacing
///
/// Gets or sets the Horizontal spacing around tab elements
///
[Browsable(true), DefaultValue(5), Category("Appearance")]
[Description("Indicates the Horizontal spacing around tab elements.")]
public int TabHorizontalSpacing
{
get { return (_TabStrip.TabHorizontalSpacing); }
set { _TabStrip.TabHorizontalSpacing = value; }
}
#endregion
#region TabLayoutType
///
/// Gets or sets the type of the tab layout
///
[Browsable(true), DefaultValue(eSuperTabLayoutType.SingleLine), Category("Appearance")]
[Description("Indicates the type of the tab layout.")]
public eSuperTabLayoutType TabLayoutType
{
get { return (_TabStrip.TabLayoutType); }
set { _TabStrip.TabLayoutType = value; }
}
#endregion
#region Tabs
///
/// Gets the collection of Tabs
///
[Editor("DevComponents.DotNetBar.Design.SuperTabControlTabsEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Category("Data"), Description("Indicates the collection of Tabs.")]
public SubItemsCollection Tabs
{
get { return (_TabStrip.Tabs); }
}
#endregion
#region TabStrip
///
/// Gets the control TabStrip
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SuperTabStrip TabStrip
{
get { return (_TabStrip); }
}
#endregion
#region TabStripColor
///
/// Gets or sets the Color of the TabStrip
///
[Browsable(true), Category("Appearance")]
[Description("Indicates the Color of the TabStrip.")]
public SuperTabColorTable TabStripColor
{
get { return (_TabStrip.TabStripColor); }
set { _TabStrip.TabStripColor = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTabStripColor()
{
return (_TabStrip.TabStripColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTabStripColor()
{
_TabStrip.TabStripColor = new SuperTabColorTable();
}
#endregion
#region TabStyle
///
/// Gets or sets the tab style
///
[Browsable(true), DevCoBrowsable(true), DefaultValue(eSuperTabStyle.Office2007)]
[Category("Appearance"), Description("Indicates the tab style.")]
public eSuperTabStyle TabStyle
{
get { return (_TabStrip.TabStyle); }
set
{
if (_TabStrip.TabStyle != value)
{
_TabStrip.TabStyle = value;
RefreshPanelsStyle();
}
}
}
#endregion
#region TabVerticalSpacing
///
/// Gets or sets the Vertical spacing around tab elements
///
[Browsable(true), DefaultValue(4), Category("Appearance")]
[Description("Indicates the Vertical spacing around tab elements.")]
public int TabVerticalSpacing
{
get { return (_TabStrip.TabVerticalSpacing); }
set { _TabStrip.TabVerticalSpacing = value; }
}
#endregion
#region TabsVisible
///
/// Gets or sets whether tabs are visible
///
[DefaultValue(true), Category("Appearance")]
[Description("Indicates whether tabs are visible")]
public bool TabsVisible
{
get { return (_TabsVisible); }
set
{
if (_TabsVisible != value)
{
_TabsVisible = value;
_TabStrip.Visible = value;
RefreshPanelsStyle();
}
}
}
#endregion
#endregion
#region TextAlignment
///
/// Gets or sets tab text alignment
///
[Browsable(true), DefaultValue(eItemAlignment.Near)]
[DevCoBrowsable(true), Category("Layout"), Description("Indicates tab text alignment.")]
public eItemAlignment TextAlignment
{
get { return (_TabStrip.TextAlignment); }
set { _TabStrip.TextAlignment = value; }
}
#endregion
#endregion
#region HookEvents
///
/// Hooks (or unhooks) underlying TabStrip events
///
/// true to hook, false to unhook
private void HookEvents(bool hook)
{
if (hook == true)
{
_TabStrip.TabItemOpen += TabStripTabItemOpen;
_TabStrip.TabItemClose += TabStripTabItemClose;
_TabStrip.TabRemoved += TabStripTabRemoved;
_TabStrip.TabMoving += TabStripTabMoving;
_TabStrip.TabMoved += TabStripTabMoved;
_TabStrip.SelectedTabChanging += TabStripSelectedTabChanging;
_TabStrip.SelectedTabChanged += TabStripSelectedTabChanged;
_TabStrip.GetTabItemPath += TabStripItemGetTabItemPath;
_TabStrip.GetTabItemContentRectangle += TabStripItemGetTabItemContentRectangle;
_TabStrip.BeforeTabDisplay += TabStripBeforeTabDisplay;
_TabStrip.MeasureTabItem += TabStripMeasureTabItem;
_TabStrip.PreRenderTabItem += TabStripPreRenderTabItem;
_TabStrip.PostRenderTabItem += TabStripPostRenderTabItem;
_TabStrip.GetTabTextBounds += TabStripGetTabTextBounds;
_TabStrip.GetTabImageBounds += TabStripGetTabImageBounds;
_TabStrip.GetTabCloseBounds += TabStripGetTabCloseBounds;
_TabStrip.TabStripPaintBackground += TabStripTabStripPaintBackground;
_TabStrip.TabStripTabColorChanged += TabStripTabColorChanged;
_TabStrip.MouseUp += TabStrip_MouseUp;
_TabStrip.MouseDown += TabStrip_MouseDown;
_TabStrip.MouseMove += TabStrip_MouseMove;
_TabStrip.MouseClick += TabStrip_MouseClick;
_TabStrip.MouseDoubleClick += TabStrip_MouseDoubleClick;
_TabStrip.MouseEnter += TabStrip_MouseEnter;
_TabStrip.MouseHover += TabStrip_MouseHover;
_TabStrip.MouseLeave += TabStrip_MouseLeave;
}
else
{
_TabStrip.TabItemOpen -= TabStripTabItemOpen;
_TabStrip.TabItemClose -= TabStripTabItemClose;
_TabStrip.TabRemoved -= TabStripTabRemoved;
_TabStrip.TabMoving -= TabStripTabMoving;
_TabStrip.TabMoved -= TabStripTabMoved;
_TabStrip.SelectedTabChanging -= TabStripSelectedTabChanging;
_TabStrip.SelectedTabChanged -= TabStripSelectedTabChanged;
_TabStrip.GetTabItemPath -= TabStripItemGetTabItemPath;
_TabStrip.GetTabItemContentRectangle -= TabStripItemGetTabItemContentRectangle;
_TabStrip.BeforeTabDisplay -= TabStripBeforeTabDisplay;
_TabStrip.MeasureTabItem -= TabStripMeasureTabItem;
_TabStrip.PreRenderTabItem -= TabStripPreRenderTabItem;
_TabStrip.PostRenderTabItem -= TabStripPostRenderTabItem;
_TabStrip.GetTabTextBounds -= TabStripGetTabTextBounds;
_TabStrip.GetTabImageBounds -= TabStripGetTabImageBounds;
_TabStrip.GetTabCloseBounds -= TabStripGetTabCloseBounds;
_TabStrip.TabStripPaintBackground -= TabStripTabStripPaintBackground;
_TabStrip.TabStripTabColorChanged -= TabStripTabColorChanged;
_TabStrip.MouseUp -= TabStrip_MouseUp;
_TabStrip.MouseDown -= TabStrip_MouseDown;
_TabStrip.MouseMove -= TabStrip_MouseMove;
_TabStrip.MouseClick -= TabStrip_MouseClick;
_TabStrip.MouseDoubleClick -= TabStrip_MouseDoubleClick;
_TabStrip.MouseEnter -= TabStrip_MouseEnter;
_TabStrip.MouseHover -= TabStrip_MouseHover;
_TabStrip.MouseLeave -= TabStrip_MouseLeave;
}
}
#endregion
#region Event processing
#region TabItemOpen
///
/// Handles TabItemOpen events
///
///
///
void TabStripTabItemOpen(object sender, SuperTabStripTabItemOpenEventArgs e)
{
if (TabItemOpen != null)
TabItemOpen(this, e);
}
#endregion
#region TabItemClose
///
/// Handles TabItemClose events
///
///
///
void TabStripTabItemClose(object sender, SuperTabStripTabItemCloseEventArgs e)
{
if (TabItemClose != null)
TabItemClose(this, e);
}
#endregion
#region TabMoving
///
/// Handles TabMoving events
///
///
///
void TabStripTabMoving(object sender, SuperTabStripTabMovingEventArgs e)
{
if (TabMoving != null)
TabMoving(this, e);
}
#endregion
#region TabMoved
///
/// Handles TabMoved events
///
///
///
void TabStripTabMoved(object sender, SuperTabStripTabMovedEventArgs e)
{
if (TabMoved != null)
TabMoved(this, e);
}
#endregion
#region TabRemoved
///
/// Handles TabRemoved events
///
///
///
void TabStripTabRemoved(object sender, SuperTabStripTabRemovedEventArgs e)
{
if (TabRemoved != null)
TabRemoved(this, e);
}
#endregion
#region SelectedTabChanging
///
/// Handles SelectedTabChanging events
///
///
///
void TabStripSelectedTabChanging(object sender, SuperTabStripSelectedTabChangingEventArgs e)
{
if (SelectedTabChanging != null)
SelectedTabChanging(this, e);
}
#endregion
#region SelectedTabChanged
///
/// Handles SelectedTabChanged events
///
///
///
void TabStripSelectedTabChanged(object sender, SuperTabStripSelectedTabChangedEventArgs e)
{
if (SelectedTabChanged != null)
SelectedTabChanged(this, e);
}
#endregion
#region GetTabItemPath
///
/// Handles GetTabItemPath events
///
///
///
void TabStripItemGetTabItemPath(object sender, SuperTabGetTabItemPathEventArgs e)
{
if (GetTabItemPath != null)
GetTabItemPath(this, e);
}
#endregion
#region GetTabItemContentRectangle
///
/// Handles GetTabItemContentRectangle events
///
///
///
void TabStripItemGetTabItemContentRectangle(object sender, SuperTabGetTabItemContentRectangleEventArgs e)
{
if (GetTabItemContentRectangle != null)
GetTabItemContentRectangle(this, e);
}
#endregion
#region BeforeTabDisplay
///
/// Handles BeforeTabDisplay events
///
///
///
void TabStripBeforeTabDisplay(object sender, SuperTabStripBeforeTabDisplayEventArgs e)
{
if (BeforeTabDisplay != null)
BeforeTabDisplay(this, e);
}
#endregion
#region MeasureTabItem
///
/// Handles MeasureTabItem events
///
///
///
void TabStripMeasureTabItem(object sender, SuperTabMeasureTabItemEventArgs e)
{
if (MeasureTabItem != null)
MeasureTabItem(this, e);
}
#endregion
#region PreRenderTabItem
///
/// Handles PreRenderTabItem events
///
///
///
void TabStripPreRenderTabItem(object sender, SuperTabPreRenderTabItemEventArgs e)
{
if (PreRenderTabItem != null)
PreRenderTabItem(this, e);
}
#endregion
#region PostRenderTabItem
///
/// Handles PostRenderTabItem events
///
///
///
void TabStripPostRenderTabItem(object sender, SuperTabPostRenderTabItemEventArgs e)
{
if (PostRenderTabItem != null)
PostRenderTabItem(this, e);
}
#endregion
#region GetTabCloseBounds
///
/// Handles GetTabCloseBounds events
///
///
///
void TabStripGetTabCloseBounds(object sender, SuperTabGetTabCloseBoundsEventArgs e)
{
if (GetTabCloseBounds != null)
GetTabCloseBounds(this, e);
}
#endregion
#region GetTabImageBounds
///
/// Handles GetTabImageBounds events
///
///
///
void TabStripGetTabImageBounds(object sender, SuperTabGetTabImageBoundsEventArgs e)
{
if (GetTabImageBounds != null)
GetTabImageBounds(this, e);
}
#endregion
#region GetTabTextBounds
///
/// Handles GetTabTextBounds events
///
///
///
void TabStripGetTabTextBounds(object sender, SuperTabGetTabTextBoundsEventArgs e)
{
if (GetTabTextBounds != null)
GetTabTextBounds(this, e);
}
#endregion
#region TabStripPaintBackground
///
/// Handles TabStripPaintBackground events
///
///
///
void TabStripTabStripPaintBackground(object sender, SuperTabStripPaintBackgroundEventArgs e)
{
if (TabStripPaintBackground != null)
TabStripPaintBackground(this, e);
}
#endregion
#region StyleManagerStyleChanged
///
/// Handles StyleManagerStyleChanged events
///
///
[EditorBrowsable(EditorBrowsableState.Never)]
public void StyleManagerStyleChanged(eDotNetBarStyle newStyle)
{
RefreshPanelsStyle();
}
#endregion
#region TabStripTabColorChanged
///
/// Handles TabStripTabColorChanged events
///
///
///
void TabStripTabColorChanged(object sender, SuperTabStripTabColorChangedEventArgs e)
{
SuperTabControlPanel panel = e.Tab.AttachedControl as SuperTabControlPanel;
if (panel != null)
ApplyPanelStyle(panel);
}
#endregion
#region TabStrip_MouseUp
///
/// Handles TabStrip_MouseUp events
///
///
///
void TabStrip_MouseUp(object sender, MouseEventArgs e)
{
if (TabStripMouseUp != null)
TabStripMouseUp(sender, e);
}
#endregion
#region MouseDown
///
/// Handles TabStrip_MouseDown events
///
///
///
void TabStrip_MouseDown(object sender, MouseEventArgs e)
{
if (TabStripMouseDown != null)
TabStripMouseDown(sender, e);
}
#endregion
#region MouseMove
///
/// Handles TabStrip_MouseMove events
///
///
///
void TabStrip_MouseMove(object sender, MouseEventArgs e)
{
if (TabStripMouseMove != null)
TabStripMouseMove(sender, e);
}
#endregion
#region MouseClick
///
/// Handles TabStrip_MouseClick events
///
///
///
void TabStrip_MouseClick(object sender, MouseEventArgs e)
{
if (TabStripMouseClick != null)
TabStripMouseClick(sender, e);
}
#endregion
#region MouseDoubleClick
///
/// Handles TabStrip_MouseDoubleClick events
///
///
///
void TabStrip_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (TabStripMouseDoubleClick != null)
TabStripMouseDoubleClick(sender, e);
}
#endregion
#region MouseEnter
///
/// Handles TabStrip_MouseEnter events
///
///
///
void TabStrip_MouseEnter(object sender, EventArgs e)
{
if (TabStripMouseEnter != null)
TabStripMouseEnter(sender, e);
}
#endregion
#region MouseHover
///
/// Handles TabStrip_MouseHover events
///
///
///
void TabStrip_MouseHover(object sender, EventArgs e)
{
if (TabStripMouseHover != null)
TabStripMouseHover(sender, e);
}
#endregion
#region MouseLeave
///
/// Handles TabStrip_MouseLeave events
///
///
///
void TabStrip_MouseLeave(object sender, EventArgs e)
{
if (TabStripMouseLeave != null)
TabStripMouseLeave(sender, e);
}
#endregion
#endregion
#region DefaultSize
///
/// Gets the DefaultSize
///
protected override Size DefaultSize
{
get { return new Size(200, 100); }
}
#endregion
#region CreateTab
///
/// Creates a TabControl tab
///
///
///
public SuperTabItem CreateTab(string tabText)
{
return (CreateTab(tabText, -1));
}
///
/// Creates a TabControl tab
///
///
///
///
public SuperTabItem CreateTab(string tabText, int insertAt)
{
SuperTabItem tab = new SuperTabItem();
SuperTabControlPanel panel = new SuperTabControlPanel();
tab.Text = tabText;
return (CreateTab(tab, panel, insertAt));
}
///
/// Creates a TabControl tab
///
///
///
///
///
[EditorBrowsable(EditorBrowsableState.Never)]
public SuperTabItem CreateTab(SuperTabItem tab, SuperTabControlPanel panel, int insertAt)
{
SuspendLayout();
tab.AttachedControl = panel;
panel.TabItem = tab;
Controls.Add(panel);
if (insertAt < 0 || insertAt >= Tabs.Count)
Tabs.Add(tab);
else
Tabs.Insert(insertAt, tab);
ApplyPanelStyle(panel);
panel.Size = Size.Empty;
panel.Dock = DockStyle.Fill;
panel.BringToFront();
ResumeLayout();
return (tab);
}
#endregion
#region SelectPreviousTab
///
/// Selects the previous tab
///
/// true if tab selected
public bool SelectPreviousTab()
{
return (_TabStrip.SelectPreviousTab());
}
#endregion
#region SelectNextTab
///
/// Selects the next tab
///
/// true if tab selected
public bool SelectNextTab()
{
return (_TabStrip.SelectNextTab());
}
#endregion
#region GetTabFromPoint
///
/// Gets the SuperTabItem tab containing the given Point
///
/// Point to test
/// Associated tab, or null
public SuperTabItem GetTabFromPoint(Point pt)
{
return (_TabStrip.GetTabFromPoint(pt));
}
#endregion
#region GetItemFromPoint
///
/// Gets the item (SuperTabItem or BaseView) associated
/// with the given Point
///
/// Point to test
/// BaseItem or null
public BaseItem GetItemFromPoint(Point pt)
{
return (_TabStrip.GetItemFromPoint(pt));
}
#endregion
#region CloseTab
///
/// Closes the given tab
///
///
public void CloseTab(SuperTabItem tab)
{
_TabStrip.CloseTab(tab);
}
#endregion
#region RecalcLayout
///
/// Causes a Layout Recalculation of the SuperTabControl
///
public void RecalcLayout()
{
_TabStrip.RecalcLayout();
}
#endregion
#region RefreshPanelStyle
///
/// Refreshes all panel styles
///
internal void RefreshPanelsStyle()
{
if (_Initializing == false)
{
foreach (Control c in Controls)
{
if (c is SuperTabControlPanel)
ApplyPanelStyle(c as SuperTabControlPanel);
}
}
}
#endregion
#region ApplyPanelStyle
///
/// Applies color and border settings to the given panel
///
///
public void ApplyPanelStyle(SuperTabControlPanel panel)
{
if (panel != null && panel.TabItem != null && panel.TabItem.TabStripItem != null)
{
ElementStyle style = new ElementStyle();
ApplyPanelColor(panel, style);
ApplyPanelBorder(style);
style.BackgroundImage = panel.BackgroundImage;
style.BackgroundImagePosition = panel.BackgroundImagePosition;
panel.PanelStyle = style;
}
}
#region ApplyPanelColor
///
/// Applies color settings to the given panel
///
///
///
private void ApplyPanelColor(
SuperTabControlPanel panel, ElementStyle style)
{
SuperTabPanelItemColorTable pct = panel.TabItem.GetPanelColorTable();
SuperTabItemStateColorTable sct = panel.TabItem.GetTabColorTable(eTabState.Selected);
int angle;
bool? adaptiveGradient;
// If we have PanelColorTable settings, use them. If not, use
// the current StateColorTable panel settings
if (pct.Background.IsEmpty == false)
{
angle = pct.Background.GradientAngle;
adaptiveGradient = pct.Background.AdaptiveGradient ?? sct.Background.AdaptiveGradient;
style.BackColorBlend.Clear();
if (pct.Background.Colors != null)
{
if (pct.Background.Colors.Length > 2)
{
style.BackColorBlend.CopyFrom(pct.Background.GetColorBlendCollection());
}
else
{
style.BackColor = pct.Background.Colors[0];
style.BackColor2 = (pct.Background.Colors.Length == 1) ?
pct.Background.Colors[0] : pct.Background.Colors[1];
}
}
}
else
{
angle = sct.Background.GradientAngle;
adaptiveGradient = sct.Background.AdaptiveGradient;
if (sct.Background.Colors != null)
{
style.BackColor = sct.Background.Colors[0];
style.BackColor2 = (sct.Background.Colors.Length == 1) ?
sct.Background.Colors[0] : sct.Background.Colors[1];
}
}
// If we have an adaptive gradient, alter the gradient
// angle to correspond to the current tab alignment
if (adaptiveGradient != false)
{
switch (_TabStrip.TabAlignment)
{
case eTabStripAlignment.Top:
style.BackColorGradientAngle = angle - 180;
break;
case eTabStripAlignment.Bottom:
style.BackColorGradientAngle = angle;
break;
case eTabStripAlignment.Left:
style.BackColorGradientAngle = angle + 90;
break;
case eTabStripAlignment.Right:
style.BackColorGradientAngle = angle - 90;
break;
}
}
// Set the panel's inner and outer border colors
style.BorderColor = pct.OuterBorder;
style.BorderColorLight = pct.InnerBorder;
}
#endregion
#region ApplyPanelBorder
///
/// Applies border settings for the given panel
///
///
private void ApplyPanelBorder(ElementStyle style)
{
if (TabsVisible == true)
{
style.BorderWidth = 0;
if (style.BorderColor.IsEmpty == false)
style.BorderWidth++;
if (style.BorderWidth == 0)
style.Border = eStyleBorderType.None;
else if (style.BorderColorLight.IsEmpty)
style.Border = eStyleBorderType.Solid;
else
style.Border = eStyleBorderType.Double;
if (_TabStrip.Available == true)
{
switch (_TabStrip.TabAlignment)
{
case eTabStripAlignment.Top:
style.BorderTop = eStyleBorderType.None;
break;
case eTabStripAlignment.Bottom:
style.BorderBottom = eStyleBorderType.None;
break;
case eTabStripAlignment.Left:
style.BorderLeft = eStyleBorderType.None;
break;
case eTabStripAlignment.Right:
style.BorderRight = eStyleBorderType.None;
break;
}
}
}
else
{
style.Border = eStyleBorderType.None;
}
}
#endregion
#endregion
#region OnSystemColorsChanged
///
/// Performs OnSystemColorsChanged processing
///
///
protected override void OnSystemColorsChanged(EventArgs e)
{
base.OnSystemColorsChanged(e);
Application.DoEvents();
RefreshPanelsStyle();
}
#endregion
#region OnResize
///
/// Performs OnResize processing
///
///
/// NOT NEEDED. Let WinForms layout do the work!
//protected override void OnResize(EventArgs e)
//{
// base.OnResize(e);
// if (_TabStrip != null)
// _TabStrip.Size = Size;
//}
protected override void OnHandleCreated(EventArgs e)
{
// This will make sure that layout is performed by WinForms
BarUtilities.InvokeDelayed(new MethodInvoker(delegate
{
if (_TabStrip.Dock == DockStyle.Top || _TabStrip.Dock == DockStyle.Bottom)
_TabStrip.Width = this.ClientRectangle.Width;
else if (_TabStrip.Dock == DockStyle.Left || _TabStrip.Dock == DockStyle.Right)
_TabStrip.Height = this.ClientRectangle.Height;
}
), 100);
base.OnHandleCreated(e);
}
#endregion
#region OnControlAdded
///
/// OnControlAdded
///
///
protected override void OnControlAdded(ControlEventArgs e)
{
base.OnControlAdded(e);
if (DesignMode == false)
{
SuperTabControlPanel panel = e.Control as SuperTabControlPanel;
if (panel != null)
{
if (panel.TabItem != null)
{
if (this.Tabs.Contains(panel.TabItem) && this.SelectedTab == panel.TabItem)
{
panel.Visible = true;
panel.BringToFront();
}
else
panel.Visible = false;
}
else
{
panel.Visible = false;
}
}
}
}
#endregion
#region OnControlRemoved
///
/// OnControlRemoved
///
///
protected override void OnControlRemoved(ControlEventArgs e)
{
base.OnControlRemoved(e);
SuperTabControlPanel panel = e.Control as SuperTabControlPanel;
if (panel != null)
{
if (panel.TabItem != null)
{
if (Tabs.Contains(panel.TabItem))
Tabs.Remove(panel.TabItem);
}
}
}
#endregion
#region ISupportInitialize Members
///
/// BeginInit
///
void ISupportInitialize.BeginInit()
{
_Initializing = true;
}
///
/// EndInit
///
void ISupportInitialize.EndInit()
{
_Initializing = false;
// Apply default panel style
RefreshPanelsStyle();
// Establish our initial selected tab
SuperTabItem tab =
_TabStrip.TabStripItem.GetNewSelectTab(_LoadSelectedTabIndex);
if (tab != null)
{
SelectedTab = tab;
if (_TabStrip.SelectedTab != null && _TabStrip.SelectedTab.AttachedControl != null)
{
_TabStrip.SelectedTab.AttachedControl.Visible = true;
_TabStrip.SelectedTab.AttachedControl.BringToFront();
}
}
if (this.DesignMode && this.SelectedTab!=null)
{
foreach (BaseItem item in _TabStrip.Tabs)
{
SuperTabItem tabItem = item as SuperTabItem;
if (tabItem != null && tabItem != this.SelectedTab && tabItem.AttachedControl != null)
tabItem.AttachedControl.Visible = false;
}
}
_LoadSelectedTabIndex = -1;
// Make sure the pending layout is performed following
// the designer initialization
//ResumeLayout(true); // Bad idea since it messes up layout when controls created with 96 DPI are loaded in environment greater than 96 DPI, like 120 DPI etc.
}
#endregion
#region ValidateFormOnTabSelection
private bool _ValidateFormOnTabSelection = true;
///
/// Indicates whether Form.Validate is called and checked before selected tab is changed. Default value is true.
///
[DefaultValue(true), Category("Behavior"), Description("Indicates whether Form.Validate is called and checked before selected tab is changed.")]
public bool ValidateFormOnTabSelection
{
get { return _ValidateFormOnTabSelection; }
set
{
_ValidateFormOnTabSelection = value;
}
}
#endregion
}
}
#endif