Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I dynamically embed a winform subform into the tab control of a main winform?

Is there a way that I can hand a Winforms form object to a main form containing a tab control, and have the main form load this form object into one of the tabs?

An additional wrinkle: the form object will be instantiated from a different thread than the main form.

like image 778
Robert Harvey Avatar asked Jan 19 '23 16:01

Robert Harvey


2 Answers

I don't think it will work when the Forms are created on different threads, but you would normally do this by setting the Form's TopLevel property to False and then adding it to the tab page control (or any other parent control).

Edit: You also need to set the Visible property to True because Forms are hidden by default.

Also, I just tried this and it does work for something like a button created from another thread. But when I did it with a Form, I got an InvalidOperationException.

like image 87
Mike Dour Avatar answered Jan 30 '23 23:01

Mike Dour


Do you want something like Multi Document Interface (MDI) tab page browsing?

like image 30
SwDevMan81 Avatar answered Jan 31 '23 00:01

SwDevMan81