4 Replies - 2735 Views - Last Post: 18 November 2010 - 04:25 PM Rate Topic: -----

#1 Guest_tehwabbit*


Reputation:

Visual C# Forms : Auto create Tab contents

Posted 17 November 2010 - 04:08 PM

Using Visual C# in VS2008.


I have the need to create multiple tabs in my application so it displays a bit like Chrome, I am using a default tab-box control "mainScreen" as a base and have another control calling
Code:
mainScreen.TabPages.Add(selectedprogram.Name);



Is there a way of setting it up so that when I create a new tab, there are already predefined controls in it? e.g. Name field, Description Field.
(Perhaps a predefined form to import?)

The only way I can think of is to have a function where I manually draw the tabbed-page's contents and populate them from here, this, however would not be suitable - I need to do a lot of UI testing so needs to be made in the WYSISYG editor - THat, and I'm a noob at manually coding GUIs outside the sandbox!

This post has been edited by modi123_1: 17 November 2010 - 07:47 PM
Reason for edit:: code tags


Is This A Good Question/Topic? 0

Replies To: Visual C# Forms : Auto create Tab contents

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9096
  • View blog
  • Posts: 34,161
  • Joined: 12-June 08

Re: Visual C# Forms : Auto create Tab contents

Posted 17 November 2010 - 07:49 PM

Just a pointer in the right direction - your GUI controls are just objects, right? You can create objects and add them to a control's container.

Basically every time you would add a new tab you could generate your standard set of control objects (give them unique names) and add them to the new tab control!

Here's a great example of adding controls on the fly.
http://en.csharp-onl...ols_at_Run_Time
Was This Post Helpful? 0
  • +
  • -

#3 mavarazo  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 182
  • Joined: 25-October 10

Re: Visual C# Forms : Auto create Tab contents

Posted 17 November 2010 - 11:40 PM

Are you asking for something like that?

string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);


Was This Post Helpful? 0
  • +
  • -

#4 tehwabbit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-November 10

Re: Visual C# Forms : Auto create Tab contents

Posted 18 November 2010 - 07:43 AM

Thanks for the quick response!

So am I right in thinking that I could use something like:


public void populateTab(TabPage name){

Button testbutton = new Button();

testbutton.text = name;

//bad example, I know!
}




etc..


Then call


mainScreen.TabPages.Add(selectedprogram.Name);
populateTab(selectedprogram.Name);
Was This Post Helpful? 0
  • +
  • -

#5 tehwabbit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 18-November 10

Re: Visual C# Forms : Auto create Tab contents

Posted 18 November 2010 - 04:25 PM

View Postmavarazo, on 17 November 2010 - 10:40 PM, said:

Are you asking for something like that?

string title = "TabPage " + (tabControl1.TabCount + 1).ToString();
TabPage myTabPage = new TabPage(title);
tabControl1.TabPages.Add(myTabPage);



Right, I have coded up my dynamically built interface, now... how would you go about adding eventhandlers to these? Hmmm

I tried following http://en.csharp-onl...ommand_Controls with my code:

//inside newly created tabpage
 Button closeTab = new Button();
            closeTab.Location = new Point(1, 1);
            closeTab.Text = "X";




 private void closeTab_Click(object sender, EventArgs e)
        {
            this.Text = "Y";
        }



I have the line:

closeTab.Click += new System.EventHandler(this.closeTab_Click);

To put somewhere, but everywhere I put it, it either doesn't work or throws up errors

This post has been edited by tehwabbit: 18 November 2010 - 04:34 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1