Can't add tabpages from a seperate class
Good evening folks, I'm building a program that is threaded. While I can get the thread to work no problem, I can not seem to add pages to my tabcontrol from the class I'm using. Any idea's on what I'm doing wrong?
frmMain is loaded first. Then the idea is to load the other tabpages using a separate thread as they take awhile.
Code:
Dim myformCal As New FrmCalender 'Load a new frmCalendar
myformCal.TopLevel = False 'Make sure form is not top level
myformCal.Dock = DockStyle.Fill 'Make sure to fit main form
frmmain.tpCalendar.Controls.Add(myformCal)
myformCal.Show() 'Show Form
Any help would be appreciated.
Redmo
Re: Can't add tabpages from a seperate class
Arae you saying that that code is running on a thread other than the main thread? If so then that's bad because you really should not be creating forms on different threads without a good reason.
Apart from that, you can't access frmMain from a thread other than the UI thread. Either you're using the default instance there and you're actually adding tabs to a form you can't see or you're performing an illegal cross-thread operation. My guess is it's the first one. In that case I suggest that you follow the Blog link in my signature and read the post on default instances. It's OK to load data requiredby a form in a bakcground thread but anything that actually affects the form itself MUST be done in the UI thread. To see how, follow the CodeBank link in my signature and check out my post on access controls from worker threads.