Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Create and edit a TabPage as a stand alone object
 

Create and edit a TabPage as a stand alone object

With MFC / C++ one was able to edit "Property Pages" as stand alone objects which were then added to the "Property Sheet" (tab control) In the .net world one can add and remove TabPage item from the TabControl. The problem is that one can only edit the tab pages as they sit in the tab control which sits in the form that hosts TabControl.

To be brief when one adds a form to project one gets a class derived from System.Woindows.Forms.Form and the capability to drag and drop controls from the tool box onto said form. But this capability does not exsit to create a tab page (i.e. a class derived from TabPage and not Form) with direct drag and drop resource editing.

So is there way to create a class derived from TabPage from with in Dev Studio which would then allow the resource editor to work as so as to allow the positioning of controls, mapping of events and so on?

P.S. I do have a work around that involves making a "UserControl" in the project which allows full WYSISYG editing then embedding said control in the class derived from TabPage. But it would be better if a TabPage class could be created that allowed full WYSISYG editing from the tool box.
  • Edited byMaroy1 Friday, June 19, 2009 3:56 PMtypo
  •  
Maroy1  Friday, June 19, 2009 3:00 PM
TabPages can only be added to TabControls, so you can't add a TabPage to the DesignerFrame. I'm sure that there will be some very complicated way to do it, but why go to all that effort?

Easiest solution is to create the TabPage as a UserControl, like you're already doing, and once happy with the design, close the Designer and change inheritance to TabPage. Just make sure that you change inheritance back to UserControl before you open up the Designer again to make any changes.
Mick Doherty
http://dotnetrix.co.uk
  • Marked As Answer byMaroy1 Monday, June 22, 2009 5:58 PM
  •  
Mick Doherty  Friday, June 19, 2009 7:47 PM
TabPages can only be added to TabControls, so you can't add a TabPage to the DesignerFrame. I'm sure that there will be some very complicated way to do it, but why go to all that effort?

Easiest solution is to create the TabPage as a UserControl, like you're already doing, and once happy with the design, close the Designer and change inheritance to TabPage. Just make sure that you change inheritance back to UserControl before you open up the Designer again to make any changes.
Mick Doherty
http://dotnetrix.co.uk
  • Marked As Answer byMaroy1 Monday, June 22, 2009 5:58 PM
  •  
Mick Doherty  Friday, June 19, 2009 7:47 PM
I like your work around idea. It hasa different set of trade offs but works well.

I am still hoping there is simple change one can make insome XML file that tells the DesignerFrame to handle a class derived from TabPage as if it were a UserControl.
Maroy1  Friday, June 19, 2009 8:28 PM
I don't think you're going to find a simple change to achieve this.

The problem is that TabPage overrides the internal AssignParent() method to throw an error if the control is not parented in a TabControl,but as Inheritors we cannot do this as we don't have access to the AssignParent() method.

The only workaround that I can think of, is to wrap the Win32 SYSTABCONTROL32 class and have it use panels instead of TabPages. This is an awful lot of work though.

Here's a simple demonstration class which will give you a Designer for other controls (this class inherits Panel but could easily inherit any other Control).

using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace DesignableControls
{
    public class MyPanel : MyPanelBase
    {
        public MyPanel()
            : base()
        {
            this.InitializeComponent();
        }

        private void InitializeComponent()
        {
        }

    }

    [Designer("System.Windows.Forms.Design.UserControlDocumentDesigner, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(IRootDesigner))]
    public class MyPanelBase : Panel
    {
    }
}


Build this class and you will have a Panel which can be Designed as a standalone component. You can change Inheritance to GroupBox and you will have a Designable Groupbox. As soon as you change Inheritance to TabPage you get an error when you try to instantiate the Designer because the internal AssignParent() method requires that the control be parented by TabControl.

Mick Doherty
http://dotnetrix.co.uk
Mick Doherty  Saturday, June 20, 2009 9:55 AM
Agreed, Perhaps it is not too late to see this as a feature in Dev Studio 2010. Thanks the help / feedback.

Mark
  • Edited byMaroy1 Monday, June 22, 2009 6:00 PM
  •  
Maroy1  Monday, June 22, 2009 6:00 PM

You can use google to search for other answers

Custom Search

More Threads

• Collapsible property for custom control
• Triger Function In SQL2000 VB.NET?
• How to write codes to changes the sound volume
• How to read the Code Generator statements of the Parent form using CodeDomSerializer class for a control
• Case of Name property with user control
• forms designer error, vb .net 2005
• Windows Forms designer creates an error when Initialing Database connection
• Properties help
• Nested controls scaling
• How do I use AddHandler when using IDesignerHost