Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add control to the beginning of the collection?

Tags:

c#

asp.net

For example;

panel1.Controls.Add(myControl); add to end of the collection.

Is there a way to add to the beginning of the collection without replacing the one at the beginning?

panel1.Controls.AddAt(0, myControl) replaces the control at 0.

update

actually it seems to work and not replace it. i might have gotten it wrong.

like image 877
btevfik Avatar asked Apr 15 '13 05:04

btevfik


People also ask

What is C# control?

C# Control Windows Forms controls are reusable components that encapsulate user interface functionality and are used in client-side Windows applications. A button is a control, which is an interactive component that enables users to communicate with an application.


1 Answers

You can use ControlCollection.SetChildIndex method.

Sets the index of the specified child control in the collection to the specified index value.


When SetChildIndex is called, the Control referred to by the child parameter is moved to the position specified by newIndex and the other Control references in the Control.ControlCollection are reordered to accommodate the move.

like image 66
Soner Gönül Avatar answered Oct 14 '22 22:10

Soner Gönül