3xodus Posted July 14, 2005 Posted July 14, 2005 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 :) Quote Using: Visual Studio 2005/08 Languages: C#, Win32 C++, Java, PHP
penfold69 Posted July 14, 2005 Posted July 14, 2005 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. Quote
Joe Mamma Posted July 14, 2005 Posted July 14, 2005 Button bt = new Button(); TabPage tp = new TabPage("foobar"); bt.Parent = tp; tabControl1.TabPages.Add(tp); Quote 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.
3xodus Posted July 14, 2005 Author Posted July 14, 2005 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 :) Quote Using: Visual Studio 2005/08 Languages: C#, Win32 C++, Java, PHP
Joe Mamma Posted July 14, 2005 Posted July 14, 2005 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. Quote 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.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.