Results 1 to 7 of 7

Thread: Adjust Textbox size to Cursor(carat) Position[SOLVED]

  1. #1

    Thread Starter
    Junior Member Skittles's Avatar
    Join Date
    Feb 2011
    Location
    California, USA
    Posts
    31

    Adjust Textbox size to Cursor(carat) Position[SOLVED]

    I'm loading files in Binary format and displaying it in a modified Asciii format so each byte is only one character wide.
    The "records" of my files are either 596, 610 or 624 bytes long.
    When I load one of the files, I can place the Cursor(carat) at position i.e. 624 using the SelStart property.

    Is it possible to then change the width of the text box to match the position of the cursor? This will make all the Records line up within the textbox.

    Basically, I need the textbox to get thinner or wider based on the record size of my files so the records line up.

    Thank you for your time, I hope I explained this correctly,
    Joe
    Last edited by Skittles; Apr 14th, 2021 at 07:39 AM. Reason: resolved

  2. #2
    Member
    Join Date
    Jan 2021
    Posts
    39

    Re: Adjust Textbox size to Cursor(carat) Position

    Use a dummy picturebox and a dummy string to get textwidth and use it to adjust textbox width.

  3. #3

    Thread Starter
    Junior Member Skittles's Avatar
    Join Date
    Feb 2011
    Location
    California, USA
    Posts
    31

    Re: Adjust Textbox size to Cursor(carat) Position

    So I'm using a picturebox, AutoSize=True with...

    For i = 1 To 624: readResult = readResult & Chr(88): Next: Picture1.Print readResult
    It's not resizing to fit the text.
    What else am I supposed to do.

  4. #4
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    4,419

    Re: Adjust Textbox size to Cursor(carat) Position

    You could use a Label control for this.
    Set the .AutoSize property to True
    Make sure it has the same font as your Text control.
    Assign the text to the .Caption property of the Label.
    Then check the .Width of the Label control.

    Even simpler would be using the .TextWidth method of the Form

  5. #5

    Thread Starter
    Junior Member Skittles's Avatar
    Join Date
    Feb 2011
    Location
    California, USA
    Posts
    31

    Re: Adjust Textbox size to Cursor(carat) Position

    Even though the Character width is 90 twips,
    This works...
    frmFileViewer.Width = (105.4 * RecLen) + 300

  6. #6
    Member
    Join Date
    Jan 2021
    Posts
    39

    Re: Adjust Textbox size to Cursor(carat) Position

    Let Picturebox and Textbox have the same Font property.
    Picturebox can be hidden. You don't have to set any other property.

    Code:
    textbox.text ="dummy"
    textbox.width=picturebox.textwidth("dummy") + 75

    why do we have to add that 75?
    Got it by trial and error.
    Anything less than that chops off a bit of the text.

    Hope someone would explain.

  7. #7

    Thread Starter
    Junior Member Skittles's Avatar
    Join Date
    Feb 2011
    Location
    California, USA
    Posts
    31

    Re: Adjust Textbox size to Cursor(carat) Position[SOLVED]

    I'm thinking the 75 is for the border of the textbox. Since I'm also adjusting the Form, I had to add 300, to also include the scroll bar

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