Changing Location (x ve y) Of Controls By Code

Visual C# Location Property

The positions of the objects on the form are determined by their distances from the left and top edges of the form.

X feature, determines the distance from the left edge of the form of the object.

The Y property determines the distance of the object from the top of the form.

When these properties are changed from the properties panel or by dragging with the mouse, the initial location of that object is determined.

If we want to change the position of an object with the code while the program is running, we can do it as follows.

For example, to place the textBox1 object 20 pixels from the left and top:

textBox1.Location = new Point( 20, 20 );

In the example below, one of the buttons moves the object to the right by 5 pixels each time it is clicked. The other button shifts 5 pixels to the left every time it is clicked.

private void button1_Click(object sender, EventArgs e)
{
textBox1.Location = new Point(textBox1.Location.X + 5, 114);
}
 
private void button2_Click(object sender, EventArgs e)
{
textBox1.Location = new Point(textBox1.Location.X - 5, 114);
}

 

visual c# changing x y with code, moving object with code, moving left and right with code, change location of control using code

EXERCISES

There are no examples related to this subject.



COMMENTS




Read 597 times.

Online Users: 852



changing-location-x-y-of-controls-using-code