0

I created my own Tabcontrol class, derived from UserControl, beacause I don't like the design of the exisiting Tabcontrol class. It works fine, but now I want to add design-time support to the control and I have no idea how to start. I've read some tutorials but none of them explains how create a Tabcontrol. Thanks for help ;)

Edit:

public class TabListDesigner : ParentControlDesigner
{
    private DesignerVerb addVerb;
    private DesignerVerb removeVerb;
    private DesignerVerbCollection verbs;

    protected TabList TabListControl { get { return this.Control as TabList; } }

    public override DesignerVerbCollection Verbs
    {
        get
        {
            if (verbs == null)
            {
                verbs = new DesignerVerbCollection();

                addVerb = new DesignerVerb("Add TabListPage", this.AddVerbHandler) { Description = "Add a new TabListPage to the parent control." };
                removeVerb = new DesignerVerb("Remove TabListPage", this.RemoveVerbHandler) { Description = "Remove the currently selected TabListPage from the parent control." };

                verbs.Add(addVerb);
                verbs.Add(removeVerb);
            }

            return verbs;
        }
    }

    private void AddVerbHandler(object sender, EventArgs e)
    {
        this.TabListControl.Add();
    }

    private void RemoveVerbHandler(object sender, EventArgs e)
    {
        //this.RemoveSelectedTabListPage();
    }

    public override void InitializeNewComponent(IDictionary defaultValues)
    {
        base.InitializeNewComponent(defaultValues);
        this.TabListControl.Add();
        this.TabListControl.Add();
    }
}

So this is what I did, but it doesn't work. The TabListControl.Add()-method works (I tested it on runtime, but I want the designtime support)

I want to be able to: - the control should be initialized with 2 TabPages on design-time - add/remove TabPages on design-time - switch TabPages on design-time - add Controls to the different TabPages on design-time

Felix
  • 71
  • 8
  • I'm not a c# user so that may be the reason, but your question seems unclear to me. Can you elaborate on what you're trying to do, what you've tried so far and why it didn't work? – Maerlyn Mar 14 '13 at 07:57
  • Well if you don't know c# and especially windows forms, you won't be able to help me. I don't think it's necessary to post the code for the tab-control beacuse the problem is not the tab-control itself. – Felix Mar 14 '13 at 09:44

1 Answers1

1

Theoretically, you don't need to do much when it comes to rendering your control in Visual Studio - implementation of your custom UserControl will be executed and Visual Studio will draw out control on design surface where you can re-size it, arrange it, etc.

One thing to keep in mind is this.DesignMode property. In case your control is rendered in Visual Studio DesignMode will be true so that you can run some custom code if needed (or not run some code - that's why you can so often see WebService calls wrapped in if (!this.DesignMode) { } blocks in WinForms projects).

To give more advice I would need more details from you - what exactly are you trying to do (do you need some custom functionality in designer) and which version of Visual Studio you are using.

EDIT: OK, I've just looked more into the problem - seems you are in the fun times if you want to work with mouse event's since they are trapped "by design" Check out this link: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/81606909-9310-48e8-8b46-5ecafb6e8007

So, you'll have no trouble getting your custom control to update in case you are using some logic in events like Load - but for something more advanced (interaction within designer) you'll need to dig deeper. Look at this article for example (linked from: Remove original event behaviour of WinForm Control)

Community
  • 1
  • 1
nikib3ro
  • 20,366
  • 24
  • 120
  • 181
  • Ok. I use VS 2010. Well the problem is, I have to track mouse-clicks on the control while design time...(to swtich to the apppendant tab) – Felix Mar 14 '13 at 08:18