Results 1 to 12 of 12

Thread: How to space text evenly in a textbox

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    How to space text evenly in a textbox

    I need to keep score in a game for player 1 and player 2 so in the textbox I will have lines that look like this:

    Code:
          Player 1    Player 2
    
      1)  F3 - G2     H1 - Q5
      2)  H21 - J8    B10 - D3
              '           '
              '           '
     12)  G15 - U1    B1 - C33
              '           '
    103)  J11 - K2    M44 - P1
    I need to keep the spacing even so move numbers align up on the right and the distance from Player1's move to Player2's move align up on the left
    Last edited by jmsrickland; Feb 28th, 2014 at 02:04 PM.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to space text evenly in a textbox

    if you are using a fixed width font, you can just count the characters and pad with spaces

    if you are using proportional fonts (as i would be), you need to set a form or picturebox to the same font (name and size), then you can calculate the text widths using the textwidth property, and again pad with spaces

    alternatively you can try sendmessage API with EMTABSTOPS or using other drawtext APIs
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to space text evenly in a textbox

    I kind of thought there is a Tab statement that puts the text at certain columns


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Lively Member
    Join Date
    Aug 2013
    Posts
    73

    Re: How to space text evenly in a textbox

    Why not have 2 textboxes, one for each player.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: How to space text evenly in a textbox

    Quote Originally Posted by jmsrickland View Post
    I kind of thought there is a Tab statement that puts the text at certain columns
    Yes of course you can use tabs.

    Try this where text1 is a multiline text box
    Code:
    Text1.Text = "Hello" & vbTab & "There" & vbCrLf & "Mr." & vbTab & "Smith"
    Of course there are some gotchas with tabs if your data is a bit longer on one line causing it to jump a tab

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to space text evenly in a textbox

    Of course there are some gotchas with tabs
    that is why you set tabstop positions using sendmessage
    there will be many examples, if you do not find one i can dig one up
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  7. #7
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How to space text evenly in a textbox

    You could also use a grid, and make the cell borders invisible

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to space text evenly in a textbox

    Quote Originally Posted by sten2005 View Post
    Why not have 2 textboxes, one for each player.
    How then to scroll each textbox with only one vertical scrollbar?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to space text evenly in a textbox

    Quote Originally Posted by Bobbles View Post
    You could also use a grid, and make the cell borders invisible
    As long as I can scroll the cells


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  10. #10
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: How to space text evenly in a textbox

    @jmsrickland, Why use a text box and not a listview, etc that has columns.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  11. #11
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How to space text evenly in a textbox

    Quote Originally Posted by jmsrickland View Post
    As long as I can scroll the cells
    Yup.
    If there are more rows than there are visible, then a scroll bar appears, and the user can scroll.
    I have not used the Flexgrid for years, as I use the free SGrid 2 instead
    It would be quicker for you (getting up to speed) to use the Flexgrid.
    Yell out if you wish me to refresh (my 72 year old) memory on that grid.

    Rob

    PS Anyone familiar with the flexgrid can you assure us, that the horizontal and vertical rows/columns borders can be invisible ? ?
    Last edited by Bobbles; Mar 10th, 2014 at 02:52 AM. Reason: Can flexgrid cell borders be invisible ?

  12. #12
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: How to space text evenly in a textbox

    I am attaching an example demonstrating the flexgrid as a scrollable, no cell borders, list
    I am rusty on flexgrid so have not attempted to play with formatting, spacing, Font selection, etc.
    Not yet fully matching your needs. But I am sure that the flexgrid can be configured to get the exact spacing, etc that you will require.
    Yell out if you wish further help.
    Rob
    Attached Files Attached Files

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