You can use the Location property or the Left and Top properties to position a control on a form at run time.
To position a control programmatically
[Visual Basic] Button1.Location = New Point (100, 100) [C#] Button1.Location = new Point (100,100);
[Visual Basic] Button1.Left = 300 Button1.Top = 300 [C#] Button1.Left = 300; Button1.Top = 300;
To increment a control's location programmatically
[Visual Basic] Button1.Left += 200 Button1.Top += 200 [C#] Button1.Left += 200; Button1.Top += 200;
Tip Use the Location property to set a control's X and Y position simultaneously. To set a position individually, use the control's Left (X) or Top (Y) property. Do not try to implicitly set the X and Y coordinates of the Point structure that represents the button's location, because this structure contains a copy of the button's coordinates. Below, the X member of this structure is incremented by 100 — however, the copied and incremented structure is then discarded.
[Visual Basic] Dim b As Button = New Button B.Location.X += 100 [C#] Button b = new Button(); b.Location.X += 100;
Use the syntax displayed in the bullet point above to increment the button's X coordinate.
Control Manipulation on Win Forms | Controls by Category | Adding Controls to Win Forms | Anchoring Controls on Win Forms | Docking Controls on Win Forms | Layering Objects on Win Forms | Resizing Controls on Win Forms | Setting the Tab Order on Win Forms | Working with Individual Controls | Controls You can Use on Win Forms | Win Form Controls by Function