I have a a .NET 3.5 windows form which I'd like to embed into another form. Is there a quick way to turn that form into a control?
Thanks
Add the control by drawingSelect the control by clicking on it. In your form, drag-select a region. The control will be placed to fit the size of the region you selected.
Change the form to inherit from UserControl instead of Form, then fix any compile errors.
There's also a way to embed a form in a control: Here's the code in VB:
Public Shared Sub ShowFormInControl(ByRef ctl As Control, ByRef frm As Form) If ctl IsNot Nothing AndAlso frm IsNot Nothing Then frm.TopLevel = False frm.FormBorderStyle = FormBorderStyle.None frm.Dock = DockStyle.Fill frm.Visible = True ctl.Controls.Add(frm) End If End Sub
I think I acquired this code from another post on SO, but I can't remember where, so sorry if this is your code snippet!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With