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

Posted on 2007-08-10
Last Modified: 2012-05-05
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
Question by:amielDorel
    LVL 33

    Accepted Solution

    You can try this

    Label1.Left = 5
    Label1.Top = 10
    LVL 7

    Assisted Solution

    I think you can just do this:

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

    LVL 2

    Assisted Solution

    by:Vasanth S
       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.


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    WiX Installer 2 41
    prevent lose focus 6 50
    Session variables expiration ASP.NET C# 3 37
    c# PowerShell runspace woes 5 38
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now