MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

adding tabpage to another form

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp
Author Message
RobcPettit



Joined: 11 Aug 2007
Posts: 2

PostPosted: Thu Dec 13, 2007 5:17 am    Post subject: adding tabpage to another form Reply with quote

Hi, I have two forms. From form1(frmMain) I want to add tabpages to
Form2. In form1 I have:
frmMain tbe = new frmMain();
Thread thread = new Thread(new
ThreadStart(tbe.AddTab));
thread.IsBackground = true;
thread.Start();

In Form2 I have:
public delegate void mydata(String e);

public void AddTab()
{
if (this.InvokeRequired)
{
this.BeginInvoke(new mydata(TestMethod),"somestring");
}

else
{
TestMethod("rob");
}

}
private void TestMethod(String mystring)
{
String TabName = "rob";
TabPage NewTab = new TabPage(TabName);
tabControl1.TabPages.Add(NewTab);
}

It biulds ok, and runs ok, but doesnt show the tabs on Form2.
The idea is that both forms are open, from form one I scan through a
list which has been added to a treeview,(this all works). Then click
the item I want, creating a new tab in form2 each time. Then close
form1 and work with form2.
Regards Robert

Archived from group: microsoft>public>dotnet>languages>csharp
Back to top
View user's profile Send private message
Nicholas Paldino [.NET/C#



Joined: 08 Aug 2007
Posts: 71

PostPosted: Thu Dec 13, 2007 3:23 pm    Post subject: Re: adding tabpage to another form Reply with quote

Rob,

You are never showing the new form that you create. I'm assuming that
you have already created an instance of frmMain and shown it. If so, you
have to pass a delegate pointing to the AddTab method on THAT reference.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

wrote in message @d4g2000prg.googlegroups.com...
> Hi, I have two forms. From form1(frmMain) I want to add tabpages to
> Form2. In form1 I have:
> frmMain tbe = new frmMain();
> Thread thread = new Thread(new
> ThreadStart(tbe.AddTab));
> thread.IsBackground = true;
> thread.Start();
>
> In Form2 I have:
> public delegate void mydata(String e);
>
> public void AddTab()
> {
> if (this.InvokeRequired)
> {
> this.BeginInvoke(new mydata(TestMethod),"somestring");
> }
>
> else
> {
> TestMethod("rob");
> }
>
> }
> private void TestMethod(String mystring)
> {
> String TabName = "rob";
> TabPage NewTab = new TabPage(TabName);
> tabControl1.TabPages.Add(NewTab);
> }
>
> It biulds ok, and runs ok, but doesnt show the tabs on Form2.
> The idea is that both forms are open, from form one I scan through a
> list which has been added to a treeview,(this all works). Then click
> the item I want, creating a new tab in form2 each time. Then close
> form1 and work with form2.
> Regards Robert
Back to top
View user's profile Send private message
RobcPettit



Joined: 11 Aug 2007
Posts: 2

PostPosted: Thu Dec 13, 2007 12:54 pm    Post subject: Re: adding tabpage to another form Reply with quote

Thankyou for your reply. Both forms are showing. Do you meen the
reference on the form that I want to add the tab to. If so do I have
to refer to form2 even though the code is in form2.

Regards Robert
Back to top
View user's profile Send private message
Nicholas Paldino [.NET/C#



Joined: 08 Aug 2007
Posts: 71

PostPosted: Thu Dec 13, 2007 4:53 pm    Post subject: Re: adding tabpage to another form Reply with quote

Rob,

Yes. When you create the new Form2, it is a separate instance, and you
are telling the delegate to execute the method on THAT instance. So you
have to keep the instance of Form2 that you showed previously and pass that
to the delegate which gets passed to the thread.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com

wrote in message @s19g2000prg.googlegroups.com...
> Thankyou for your reply. Both forms are showing. Do you meen the
> reference on the form that I want to add the tab to. If so do I have
> to refer to form2 even though the code is in form2.
>
> Regards Robert

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Unspecified Error when adding a new form How do you resolve this issue? I reinstalled the Scirpting 5.6 exe and reinstalled the newest MDAC 2.8, what else can I do? Best regards, Sean D. Wilkins Microsoft Certified Professional (MCP) 615.232.7900 -- 800.470.3444, Ext. 235 E-mail:

adding DesignerActionLists to form when designer host has lo Hello, my Visual Studio install refuse to load any addins, nothing shows up in the addin manager. I tried wizard created addins and some I found in the internet. Apart from reinstalling Visual Studio is there anything I can try? I think I've used addins b

Problem: resizing inherited form in code - form gets smaller I've created a form to implement a wizard / tabbed dialog interface. The form is inherited from and contains a tab control and buttons for cancel, back, next/OK. It has a mode property that switches between a wizard interface (where the

inherited form can't find assembly but base form can - why? i have some custom controls in a DLL. i use these controls on my base data-entry form class. but whenever i try to create an inherited form from it, the form won't open in the designer! it gives the error: "An exception occurred while trying to create a

Adding DSN from VB.NET application Hello Could anybody tell me how to add ODBC entry (DSN for specified provider) from vb.net application - which namespace contains such object. thanks Jacek
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> C Sharp All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group