Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: How to convert a windows form to a windows control

Tags:

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

like image 561
srmark Avatar asked Apr 01 '09 16:04

srmark


People also ask

How do I create a control over form?

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.


2 Answers

Change the form to inherit from UserControl instead of Form, then fix any compile errors.

like image 159
Neil Barnwell Avatar answered Nov 02 '22 05:11

Neil Barnwell


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!

like image 32
Joey Avatar answered Nov 02 '22 07:11

Joey