Results 1 to 6 of 6

Thread: display label relative to textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    display label relative to textbox

    I use a textbox on a sizable form. At the end of the textbox I display a label.
    I want the label to stay at the position at the end of the textbox when I change the size of the form.

    How can I do that?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,967

    Re: display label relative to textbox

    Code:
    Label1.Location = New Point(TextBox1.Right - 10, TextBox1.Bittom + 6)
    Use the code in the Form_Resize event handler

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2021
    Posts
    69

    Re: display label relative to textbox

    Changed the code a little to:

    Code:
            Label2.Location = New Point(TxtSearch.Right - 20, TxtSearch.Bottom - 16)

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,967

    Re: display label relative to textbox

    It was just an example. 😁

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    23,967

    Re: display label relative to textbox

    You should note, when setting label locations you can use...

    TxtSearch.Left
    TxtSearch.Right
    TxtSearch.Top
    TxtSearch.Bottom

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    106,895

    Re: display label relative to textbox

    You have left out a significant amount of relevant information but, if the assumptions I'm forced to make are correct, you don't need any code at all. Just use the Anchor properties of the controls. If you set the Anchor of the TextBox to Left, Top and Right and the Anchor of the Label to Top and Right then the TextBox will change its Width with the form and the Label will remain in the position relative to the top-right corner. For more information and an example, follow the CodeBank link in my signature below and check out my thread on Anchor & Dock.

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