C# Setting a Label (and other components) Location in run time

C# Setting a Label (and other components) Location in run time
Label1.Location.Y = 10 or
Label1.Location.X = 5  get me an error
Error      1      Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable
amielDorelAsked:
Who is Participating?
 
hongjunCommented:
You can try this

Label1.Left = 5
Label1.Top = 10
0
 
prosh0tCommented:
I think you can just do this:

Label1.Location = new Point(5, 10);

0
 
Vasanth SCommented:
Hi,
   You cannot set the location.x and location.y value. Since Location is property which has get/set for Point, you have to set like this.


label1.Location = new System.Drawing.Point(100, 19)

Hope this helps.

Thanks,
Vaz
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.