Results 1 to 4 of 4

Thread: [2008] MDI TabControl - Including TabGroups (Now with example!)

Threaded View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    [2008] MDI TabControl - Including TabGroups (Now with example!)

    Hi,


    I have been thinking some time to try to create a MDI TabControl that behaves like the MDI TabControl in the Visual Studio 2008 (probably 2005 too) IDE.


    What am I talking about? Here are a few screenshots of the VS2008 IDE doing what my MDI TabControl can do too:

    Right-clicking brings up a menu where you can choose to create a new Horizontal or Vertical Tab Group:


    After choosing Horizontal, we get two Tab Groups. Right-clicking another Tab now allows you to create another (up to 3) Horizontal Tab Group, or you can move the Tab to the Next or Previous Tab Group:



    Here is my control in action:

    Right-clicking the Tab:


    After choosing Horizontal and moving a few more tabs to the bottom Tab Group:


    Extra: by specifying the MdiWindowListItem property, my control automatically adds a list of each TabPage text into that Menu Item, just like a MenuStrip does with ordinary MDI Forms:


    There are a few differences, for example, my control supports as many Tab Groups as you like (as long as they are all Horizontal or all Vertical; it does not (yet?) support both at the same time).
    Also, in the VS2008 IDE, it is possible to drag tabs from one Tab Group to another. I think I am close to making that work, but it does not work yet so hang on!




    So, how does this work?

    First of all, I created a blank UserControl called a mdiTabGroupContainer. This container acts as the MdiClient control in an MDI Form application. It holds all the TabGroups and manages many interactions between the user and TabPages / TabGroups etc...
    The most important property is the TabGroups property, which is a custom Collection that notifies the container of any changes so they are redrawn correctly; as soon as the TabGroups collection changes, a RedrawTabGroups method is called that draws each TabGroup in the correct place, including a Splitter to make them resizable.

    The mdiTabGroup controls are the actual TabGroups (they are just custom TabControls). They handle the ContextMenuStrips and their events.

    The mdiTabPage controls are the TabPages belonging to the mdiTabGroups. They are just custom TabPages holding an extra property for the ContextMenuStrip (you can set your own ContextMenuStrip or change the existing ContextMenuStrip if you wish).


    Using the control is pretty easy. You need to add one mdiTabGroupContainer to your form (usually it will be Docked to Fill but it doesn't need to be). It will always hold one TabGroup by default, which can be accessed via the MainTabControl property.
    Any possible other TabGroups can be accessed using the TabGroups property.

    To add TabPages, you will usually use the MainTabControl just like you would use any other TabControl. You use the TabPages property of the MainTabControl.

    The mdiTabGroupContainer however also has a TabPages property, which returns ALL the TabPages, from each TabGroup. To get the TabPages from any particular TabGroup you just use the TabGroups property again to get the TabGroup of your liking and use its TabPages property.

    It will usually not be necessary to even access the other TabGroups; it is all handled internally. You just add your TabPages to the MainTabControl, and the user can decide which of these TabPages they want to put into a new TabGroup.




    Anyway, the control is not finished yet, but I will be updating it when I find the time. It is not ready to be posted yet as I'm still testing it. I am building a quick Tabbed MDI Text Editor application to test the functionality, once that is finished I will post the example here (won't be long!).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width