K
K
Kirill H2017-02-08 20:00:44
C++ / C#
Kirill H, 2017-02-08 20:00:44

How to programmatically "put" form element into c# panel?

There is a created button, for example, but it does not matter what the form element is, the main thing is that we created it somehow like this:
Button MyButon = new Button();
There is a panel on the form, how to assign a button to this panel? Everything is simple in the constructor - I took it and dragged it onto it, but programmatically how?
(Important! I don’t mean just coordinates, but to assign, i.e. if I remove the visibility for the panel, the button will disappear along with it)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2017-02-08
@KirillHelm

panel.Controls.Add(MyButton);
panel - your panel.
Controls is a property. Gets the collection of controls contained in the control.
Read more on msdn
Add (Control) - method. Adds the specified control to the collection of controls.
Read more on msdn
If you have an array of buttons, then use the AddRange method .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question