9 Replies - 4971 Views - Last Post: 16 March 2011 - 10:01 AM Rate Topic: -----

#1 Lewis XI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 11

Creating new tab with control at run time.

Posted 13 March 2011 - 04:29 AM

I am still learning C# and I need to be able to create a new tab and add a control at runtime and I am stuck on how to do it.

Also the new tab I am creating will contain the same controls that my other tabs do, is there a way to copy over the controls from that tab to this new one?

If anybody could help me out it would be much appreciated,

Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Creating new tab with control at run time.

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,659
  • Joined: 02-June 10

Re: Creating new tab with control at run time.

Posted 13 March 2011 - 07:59 AM

Here is something that might surprises you... In an unseen way ALL controls are created at runtime.

If you open Form1.Designer.cs you will see how the each and every control is created at runtime.

I find it easiest to create in reverse order. Start with the smallest, deepest 'last' control first. Then move up in hierarchy. This is because you can't place something you haven't made yet. Plus it is very human-readable, easy to follow and I can find where I have missed something But that is just a style choice.

            Button btnOne = new Button();
            btnOne.Location = new Point(50,50);
            btnOne.Text = "One";

            Panel pnlOne = new Panel();
            pnlOne.Controls.Add(btnOne);

            TabPage tpOne = new TabPage();
            tpOne.Text = "TabOne";
            tpOne.Controls.Add(pnlOne);

            TabControl tcOne = new TabControl();
            tcOne.TabPages.Add(tpOne);



You say you are recreating many controls on another tab. You might be in a situation where it is best to create a UserControl that consists of all your subcontrols. Then you just make a new instance of that UserControl for each tab.

These might help.

Bulding an application - Part 1
Building an application - Part 2
Was This Post Helpful? 4
  • +
  • -

#3 Lewis XI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 11

Re: Creating new tab with control at run time.

Posted 14 March 2011 - 01:36 PM

That's great I will have a look into it now, Thanks a lot :-)
Was This Post Helpful? 0
  • +
  • -

#4 Lewis XI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 11

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 07:43 AM

Thanks for the code but I can't seem to get it to work. The thing is I am using the DevComponents.DotNetBar TabControl, this doesn't seem to run in the same code, I have been trying to figure this out for the last few days and I am struggling, if anybody knows how to use the Devcomponents control and help me out would be great,

Thanks
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,659
  • Joined: 02-June 10

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 07:58 AM

I would suggest contacting DevCompenents.
You paid them a lot of good money for their product.
Their support people are the ones best equipped to support their product.

Of course you can't specifiy making a new
System.Windows.Forms.Controls.TabPage
if you are trying to put into a
DevComponents.Controls.Forms.TabControl or whatever their namespace is.

I would imagine they modeled their controls after the .NET equivilent.
You probably just need to specify in long-hand the types you are trying to make.

Let's see your current code, in the hopes we can help out.
Was This Post Helpful? 0
  • +
  • -

#6 Lewis XI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 11

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 08:00 AM

Yeh I have posted on the support forums but got nothing back.

So far I have this

            SuperTabControlPanel newPnl = new SuperTabControlPanel();
            SuperTabItem newTab = new SuperTabItem();
            ButtonX newBtn = new ButtonX();
            superTabControl1.Tabs.AddRange(new DevComponents.DotNetBar.BaseItem[] { newTab });

            newTab.AttachedControl = newPnl;
            newTab.GlobalItem = false;
            newTab.Name = "newTab";
            newTab.Text = "newTab";

            newPnl.Controls.Add(newBtn);
            newPnl.Dock = System.Windows.Forms.DockStyle.Fill;
            newPnl.Location = new System.Drawing.Point(0, 25);
            newPnl.Name = "newPnl";
            newPnl.Size = new System.Drawing.Size(546, 368);
            newPnl.TabIndex = 1;
            newPnl.TabItem = newTab;


As you can see I am trying my best to try and get the page to work so I have specified everything I can to do.

The tab adds but the ControlPanel doesn't show up.

Thanks
Was This Post Helpful? 0
  • +
  • -

#7 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,659
  • Joined: 02-June 10

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 08:05 AM

View PostLewis XI, on 16 March 2011 - 09:00 AM, said:

Yeh I have posted on the support forums but got nothing back.

So far I have this
Spoiler


As you can see I am trying my best to try and get the page to work so I have specified everything I can to do.

The tab adds but the ControlPanel doesn't show up.

Thanks


I don't see anyplace where you are adding ControlPanel newPnl to any other parent control.
If you don't add it to your form, then it has no home in which to be seen.

Form1.Controls.Add(newPnl);

Was This Post Helpful? 0
  • +
  • -

#8 Lewis XI  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-March 11

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 09:45 AM

Yes! That has added it to my form I didn't know that thank you,

The problem now is that it is filling the whole form (I am persuming the fact I have it set as Fill) but i need it to fill that tab. not the whole form
Was This Post Helpful? 0
  • +
  • -

#9 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 09:49 AM

Have you tried this,

superTabControl1.Tabs.Add(new SuperTabItem());


or

superTabControl1.Tabs.Add(newTab));



1) What refrence ,dll are you using? .
2)What DevExpress toolkit are you using ?

Maybe if u can give these answers the we can download them and help you .

This post has been edited by marinus: 16 March 2011 - 09:50 AM

Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,659
  • Joined: 02-June 10

Re: Creating new tab with control at run time.

Posted 16 March 2011 - 10:01 AM

View PostLewis XI, on 16 March 2011 - 10:45 AM, said:

Yes! That has added it to my form I didn't know that thank you,

The problem now is that it is filling the whole form (I am persuming the fact I have it set as Fill) but i need it to fill that tab. not the whole form


Well then you need to add it to right TabPage.Controls collection instead of the form1.Controls collection.

You seem to be getting an understanding of it. I don't think you need us to give you every answer on this from here forward. Experimentation combined with your new insight should take you far.

Now you understand that you have to be able to visualize which control is being placed inside which control. From there you just have to make sure you add the right control to the right collection - and set the location and size properties.

A decent size white-board can help a lot. Draw out a big box for hte form, then the tabControl, then the tabpages.

It really is just a case of a lot of nesting, like Russian nesting dolls... A goes into B, goes in C. Only you could have dozens of dolls, each with an infinite number of dolls inside.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1