469,579 Members | 1,239 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

How can i run a new form in a panel or usercontrol?

Hi everyone, i need some help with a tabbed interface.

I have this scenario:
1 Main Form
1 UserControl
1 Form

when main form is loaded the Usercontrol load ..
In the _load handler i want to open then Form in separate thread

here is my _load handler for usercontrol:
Expand|Select|Wrap|Line Numbers
  1.  Dim t As Threading.Thread
  2.     t = New Threading.Thread(AddressOf ShowForm2)
  3.     t.Start()
here is the ShowForm2 function
Expand|Select|Wrap|Line Numbers
  1. Private Sub ShowForm2()
  2.         Dim frmNew As New FORM
  3.         frmNew.TopLevel = False
  4.         Application.Run(frmNew)
  5.         Me.Invoke(New AddTabCallback(AddressOf Addtab), frmNew)
  6.     End Sub
and here is the code for adding a new form

Expand|Select|Wrap|Line Numbers
  1. Private Sub Addtab(ByRef tab As Form)
  2.         Me.Controls.Add(tab)
  3.         End Sub
this is the delegate declaration :
Expand|Select|Wrap|Line Numbers
  1. Public Delegate Sub AddTabCallback(ByRef tab As Form)
the problem is when i use Application.run(frmNew) , the form is created but is not visible on the usercontrol. Is visible on the threads area on visual studio

if i choose to remove the application.run(frmNew) and on sub addtab to add the folowing:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Addtab(ByRef tab As Form)
  2.         Me.Controls.Add(tab)
  3. tab.show()
  4.         End Sub
in this way the form is visible on usercontrol but is created on the main thread and i don't want that to happen.
Is there a way to use application.run() or other solution to launch the form in a usercontrol?

Thanks alot
Oct 25 '09 #1
0 959

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Benjamin Bittner | last post: by
22 posts views Thread by Woody Splawn | last post: by
9 posts views Thread by Quina | last post: by
5 posts views Thread by =?Utf-8?B?cm9nZXJfMjc=?= | last post: by
4 posts views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.