Click here to Skip to main content
15,885,546 members
Articles / Desktop Programming / Win32

KRBTabControl

Rate me:
Please Sign up or sign in to vote.
4.92/5 (61 votes)
2 Aug 2011CPOL20 min read 232.3K   16.4K   156  
This article explains how to make a custom Windows Tab Control in C#.
using System;
using System.Drawing;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace KRBTabControl
{
    partial class KRBTabControl
    {
        public class SelectedIndexChangingEventArgs : EventArgs, IDisposable
        {
            #region Instance Member

            private bool cancel = false;
            private int tabPageIndex = -1;
            private TabPageEx tabPage = null;

            #endregion

            #region Constructor

            public SelectedIndexChangingEventArgs(TabPageEx tabPage, int tabPageIndex)
            {
                this.tabPage = tabPage;
                this.tabPageIndex = tabPageIndex;
            }

            #endregion

            #region Property

            /// <summary>
            /// Gets or sets a value indicating whether the event should be canceled.
            /// </summary>
            public bool Cancel
            {
                get { return cancel; }
                set
                {
                    if (!value.Equals(cancel))
                        cancel = value;
                }
            }

            /// <summary>
            /// Gets the zero-based index of the TabPageEx in the KRBTabControl.TabPages collection.
            /// </summary>
            public int TabPageIndex
            {
                get { return tabPageIndex; }
            }

            /// <summary>
            /// Gets the TabPageEx the event is occurring for.
            /// </summary>
            public TabPageEx TabPage
            {
                get { return tabPage; }
            }

            #endregion

            #region IDisposable Members

            void IDisposable.Dispose()
            {
                GC.SuppressFinalize(this);
            }

            #endregion
        }

        public class ContextMenuShownEventArgs : EventArgs, IDisposable
        {
            #region Instance Member

            private ContextMenuStrip contextMenu = null;
            private Point menuLocation = Point.Empty;

            #endregion

            #region Constructor

            public ContextMenuShownEventArgs(ContextMenuStrip contextMenu, Point menuLocation)
            {
                this.contextMenu = contextMenu;
                this.menuLocation = menuLocation;
            }

            #endregion

            #region Property

            /// <summary>
            /// Gets the drop-down menu of the control.It shows when a user clicks the drop-down icon on the caption.
            /// </summary>
            public ContextMenuStrip ContextMenu
            {
                get { return contextMenu; }
            }

            /// <summary>
            /// Gets or sets the drop-down menu location on the screen coordinates.
            /// </summary>
            public Point MenuLocation
            {
                get { return menuLocation; }
                set 
                { 
                    menuLocation = value;
                }
            }

            #endregion

            #region IDisposable Members

            void IDisposable.Dispose()
            {
                GC.SuppressFinalize(this);
            }

            #endregion
        }
    }
}

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) ARELTEK
Turkey Turkey
Since 1998...

MCPD - Enterprise Application Developer

“Hesaplı hareket ettiğini zanneden ve onunla iftihar eyliyen dar kafalar; kurtulmağa, yükselmeğe elverişli hiç bir eser vücüda getirmezler. Kurtuluş ve yükselişi, ancak varlığına dayanan ve mülkü milletin gizli kapalı hazinelerini verimli hale getirmesini bilen, şahsi menfaatini millet menfaati uğruna feda eden, ruhu idealist, dimağı realist şahsiyetlerde aramalıdır.”

Nuri Demirağ, 1947

Comments and Discussions