Results 1 to 8 of 8

Thread: [SOLVED] Changing label location?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2010
    Posts
    26

    Resolved [SOLVED] Changing label location?

    Well, title explains all, if the users clicks on a setting the text of a label will change, but its not aligned so I want to get it aligned, anyone knows the code for this?

    Label1.Location and then?

    Label1.Location (blabla ;blabla) won't work so..
    Last edited by Imperoto; Jul 18th, 2010 at 06:19 AM. Reason: solved

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Changing label location?

    Aligned how? You might to provide a clearer explanation of EXACTLY what you want to happen.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2010
    Posts
    26

    Re: Changing label location?

    Okay, okay, so, the user can determine if he wants to use the function keys (F1-F10) or the Numpad (0-9)

    If I use the function keys, underneath the button is a label showing which function key it is, in this case it's F1.

    Now, if I change to the NumPad keys, the text of the label underneath changes to NumPad 0, but it ain't in the middle of the button, get me? Here's an image I quickly created;

    So I need to change the location of the label, but I don't know how..


  4. #4
    Addicted Member
    Join Date
    Apr 2009
    Location
    Croatia
    Posts
    201

    Re: Changing label location?

    before youchange the text, you can use lable1.location = new point(X, Y)
    in your case, you shouls change only X, and replace Y with: label1.location.Y
    im sure you can figure it out from here

    btw, i think that there is simpler solution with automatical alignment in properties, but im not really sure

  5. #5
    Member
    Join Date
    Jun 2010
    Posts
    55

    Re: Changing label location?

    To change the location, use something like this.

    vb Code:
    1. label1.location = new Point(x, y)

    To make sure it's in the middle you need to find the center of the button.

    vb Code:
    1. buttonCenter = button1.left + (button.width/2)

    Then use this to set the labels x co-ord.

    vb Code:
    1. x = buttonCenter - (label1.width/2)

    Hope this helps.

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jul 2010
    Posts
    26

    Re: Changing label location?

    Thanks guys, I've sorted it out :-)

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [SOLVED] Changing label location?

    You don't need any code at all for this:

    1. Set the Label's AutoSize property to False.
    2. Set the Label's TextAlign property to TopCenter.
    3. Align the centres of the Button and the Label (Hint: there's a button on the toolbar to do that, after you've selected both controls).

    That's it. Just make sure that the Label is wide enough to accommodate any text you might want to display and the rest happens automatically.

    For future reference, if you succinctly explain what it actually is that you want then you're likely to get the answer you want earlier. If you had said "how can I keep the text in a Label aligned to the centre of a Button" then I'd have known straight away.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jul 2010
    Posts
    26

    Re: [SOLVED] Changing label location?

    Quote Originally Posted by jmcilhinney View Post
    You don't need any code at all for this:

    1. Set the Label's AutoSize property to False.
    2. Set the Label's TextAlign property to TopCenter.
    3. Align the centres of the Button and the Label (Hint: there's a button on the toolbar to do that, after you've selected both controls).

    That's it. Just make sure that the Label is wide enough to accommodate any text you might want to display and the rest happens automatically.

    For future reference, if you succinctly explain what it actually is that you want then you're likely to get the answer you want earlier. If you had said "how can I keep the text in a Label aligned to the centre of a Button" then I'd have known straight away.
    Thanks ;-)

    It's true that I should explain more detailed and easier but hey, english isn't my mother language, so I don't always know how to explain something you see ;-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width