Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

An easy way to add a Ribbon Panel Office 2007 style

, 18 Apr 2007
GNU code of RibbonPanel, free software for personal and nonlucrative use, for rest please contact me
demo.zip
source.zip
Source
TabStripApp
archive
bin
Release
diagram.png
Example.exe
TabStripApp.pdb
TabStripApp.vshost.exe
TabStripControlLibrary.dll
TabStripControlLibrary.pdb
Properties
Settings.settings
Resources
advanced-directory.png
B_click.png
B_click1.png
B_click11.png
B_on.png
B_on1.png
B_on11.png
config-users.png
gnome-dev-harddisk-1394.png
gnome-dev-removable-usb.png
gnome-finance.png
gnome-netstatus-rx.png
gnome-searchtool-animation.png
gnome-starthere.png
logviewer.png
mozilla-thunderbird.png
pan.png
stock_contact.png
stock_mail-compose.png
stock_mail-druid.png
stock_mail-flag-for-followup-done.png
stock_mail-receive.png
stock_mail-receive1.png
stock_mail-send.png
stock_new-spreadsheet.png
stock_outbox.png
stock_weather-storm.png
Thumbs.db
xsane.png
TabStripControlLibrary
bin
Release
TabStripControlLibrary.dll
TabStripControlLibrary.pdb
Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;


namespace TabStripApp {
    [Designer(typeof(TabPageSwitcherDesigner))]
    [System.ComponentModel.DesignerCategory("code")]
    [Docking(DockingBehavior.AutoDock)]
    [ToolboxItem(false)]
    public class TabPageSwitcher : ContainerControl {
        private Control selectedControl;
        private TabStrip tabStrip;

        public TabPageSwitcher() {
            ResetBackColor();
        }

        protected override Size DefaultSize {
            get {
                return new Size(150, 150);
            }
        }
 
        protected override Padding DefaultPadding {
            get {
                return new Padding(2);
            }
        }
        public event EventHandler Load;

        public TabStrip TabStrip {
            get {
               return tabStrip;
            }
            set {
                tabStrip = value;
            }
        }
        protected override void Dispose(bool disposing) {
            base.Dispose(disposing);
        }
        protected override Control.ControlCollection CreateControlsInstance() {
            return new ZOrderControlCollection(this);
        }
        public Control SelectedControl {
            get { return selectedControl; }
            set {
                selectedControl = value;
                if (selectedControl != null) {
                    if (!Controls.Contains(value)) {
                        Controls.Add(selectedControl);
                    }
                    else {
                        selectedControl.BringToFront();
                    }
                }
            }
        }

        protected override void OnHandleCreated(EventArgs e) {
            base.OnHandleCreated(e);
            if (!RecreatingHandle) {
                OnLoad(EventArgs.Empty);
            }
        }
        protected virtual void OnLoad(EventArgs e) {
            if (this.Load != null) {
                Load(this, e);
            }

            if (!DesignMode) {
                // select a Tab 
                if (this.TabStrip != null) {
                    if (this.TabStrip.SelectedTab == null) {
                        foreach (ToolStripItem item in this.TabStrip.Items) {
                            this.TabStrip.SelectedTab = item as Tab;
                            if (this.TabStrip.SelectedTab != null) {
                                break;
                            }
                        }
                    }
                    if (this.TabStrip.SelectedTab != null) {
                        SelectedControl = this.TabStrip.SelectedTab.TabStripPage;
                    }
                }
            }
        }


        protected override void OnControlAdded(ControlEventArgs e) {
            e.Control.Dock = DockStyle.Fill;
            base.OnControlAdded(e);
        }

        #region DesignerSerialization Friendliness
        private bool ShouldSerializeBackColor() {
            return this.BackColor != ProfessionalColors.ToolStripGradientEnd;
        }
        public override void ResetBackColor() {
            this.BackColor = ProfessionalColors.ToolStripGradientEnd;
        }
        #endregion
        private class ZOrderControlCollection : Control.ControlCollection {
            public ZOrderControlCollection(Control parent) : base(parent) {
            }

            public override void SetChildIndex(Control child, int newIndex) {
                if (newIndex == Count-1) {
                    TabPageSwitcher parent = Owner as TabPageSwitcher;
                    if (parent != null && parent.SelectedControl != null && parent.SelectedControl != child) {
                        base.SetChildIndex(child, Math.Max(0,newIndex-1));
                    }
                }

                base.SetChildIndex(child, newIndex);
            }
        }

       
    }
}

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)

Share

About the Author

Juan Pablo G.C.
Software Developer Expediteapps
Spain Spain
I'm Electronic Engineer, I did my end degree project at Astrophysical Institute and Tech Institute. I'm HP Procurve AIS and ASE ,Microsoft 3.5 MCTS
I live in Canary Islands ,developing customized solutions
 
I'm developing with WPF4, SL4 MVVM, MVC3 Razor and WP7 projects, more info at my websites. Improving with Android and IOS.
 
Web:
Expediteapps


Take a look to my blog Juan Pablo G.C.
Mareinsula

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 18 Apr 2007
Article Copyright 2007 by Juan Pablo G.C.
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid