Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the location of a control on a windows form programatically using VB.net?

Tags:

vb.net

I need to change the location property of label1 from (50, 50) to (50, 70) when Button1 is clicked. This should be easy, but I can't get it to work.

like image 416
user39035 Avatar asked Feb 11 '09 01:02

user39035


People also ask

How do I change the location of a Windows form?

Position a control on the design surface of the Windows Forms Designer. In Visual Studio, drag the control to the appropriate location with the mouse. Select the control and move it with the ARROW keys to position it more precisely. Also, snaplines assist you in placing controls precisely on your form.

How do I change my location in Visual Basic?

If you've already installed it and want to change the location, you must uninstall Visual Studio and then reinstall it. In the Shared components, tools, and SDKs section, select the folder where you want to store the files that are shared by side-by-side Visual Studio installations.

In which windows of VB the property of control can be change?

Control Properties Properties can be set at design time by using the Properties window or at run time by using statements in the program code. Object is the name of the object you're customizing.

How can set the location of TextBox in VB net?

Following steps are used to set the Location property of the TextBox: Step 1 : Create a textbox using the TextBox() constructor provided by the TextBox class. // Creating textbox TextBox Mytextbox = new TextBox(); Step 2 : After creating TextBox, set the Location property of the TextBox provided by the TextBox class.


3 Answers

You can also do it this way:

label1.Location = new Point(x,y);
like image 90
msimons Avatar answered Oct 24 '22 08:10

msimons


What are you trying? I find the easiest thing to do is set the Top and Left properties individually:

label1.Left = 50;
label1.Top = 70;

Setting Location.X and Location.Y will probably result in a compile-time error, because Location is of type "Point", a value type.

like image 42
Matt Hamilton Avatar answered Oct 24 '22 08:10

Matt Hamilton


Just do like this.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Label1.Location = New Point(50, 70)
End Sub

Yes just copy & paste.

like image 36
Minion Avatar answered Oct 24 '22 07:10

Minion