Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

I'm writing a user interface for an online gaming system (found at TeamXLink.co.uk - it allows you to play XBox, PlayStation 2, Gamecube, PSP and Nontendo DS games online). The XLink engine, which does all the work tunneling packets over the Internet) is seperate from the UI, so basically you can write a UI in any language you like, so long as you communicate between the UI and engine correctly.

 

Anyway, onto my problem - I have a treeview populated with a list of online users (tvChatUsers) and a tabControl (tabPrivateMessages). I want to add a new tab to the tabControl when a user is double clicked on, the tab should contain a button, richTextBox and a textBox. I have the following code to add a tab:

  TabPage PMtab = new TabPage(e.Node.Text.ToString());
  tabChat.TabPages.Add(PMtab);
    

(e.Node.Text contains the users name)

That works fine, and adds a tabPage to the tabControl with the users name as it's .Text property.

 

The part I'm having a problem with is adding a button and textBox to the tabPage container.

 

I tried:

  TabPage PMtab = new TabPage(e.Node.Text.ToString());
  Button PMbutton = new Button();
  PMbutton.Text = "Send";
  PMtab.Container.Add(PMbutton);
  tabChat.TabPages.Add(PMtab);
    

But got the error "Use the new keyword to add an object instance." on the second to last line. I don't see how to use the new keyword here - I thought my first two lines were creating the object instances?

 

Also is it possible to name the button and textBox? - I was hoping to include the value at e.Node.Text in the name so that I know which button is being clicked - which user to send the message to.

 

Thankyou for any suggestions ro links :)

Using: Visual Studio 2005/08

Languages: C#, Win32 C++, Java, PHP

Posted

I would be tempted to create the tab page in the designer, then at runtime as the form loads, remove the tabpage from the tabcontrol.

 

Then, when a user is double-clicked, insert a new instance of the tabpage into the tabcontrol.

 

B.

Posted
Button bt = new Button();
TabPage tp = new TabPage("foobar");
bt.Parent = tp;
tabControl1.TabPages.Add(tp);

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted

penfold69 - that's one Idea I was considering, though I didn't get round to trying it. I wanted to do it through code if I could.

 

Joe Mamma that is perfect, thanks. Can't believe I din't think of .Parent :(

 

 

Thankyou both :)

Using: Visual Studio 2005/08

Languages: C#, Win32 C++, Java, PHP

Posted

your welcome. . .

might also consider creating a customcontrol . . .

change it to inherit from TabPage. . .

 

In the constructor, initialize all your child components. . .

 

then all you have to do is Add to the tab control an instance of your customtab already laid out.

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...