Results 1 to 7 of 7

Thread: Changing properties at run time for a txtbox?

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Post

    Does anyone know how to change textbox properties at run time. I am trying to control alignment through a command button but the statement txtuserarea.alignment= 0 (for left) just gives me errors. any suggestions?
    Matt

  2. #2
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    Hi Matt.

    In order to be able to change the Alignment of a text box, its Multiline Property must be set to True.

    Hope this helps.

    Chris

  3. #3

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Post

    Sure heres come code I tried to use from vb help file. text1.alignment = 0. The zero is soppose to be the setting for left justification. I have the feeling im using the wrong procedure for this.

  4. #4
    Lively Member
    Join Date
    Oct 1999
    Posts
    101

    Post

    After Martin's reply, I did some research and this is what I discovered.

    The Alignment Property is read-only at run-time in VB5. However, in VB6 it can be changed at run-time.

    If you do change it in VB6 while running your program and the Multiline Property is set to False, the Text box's alignment will not be effected by your code (e.g., it will remain Left-justified (the Default) despite the statement Text1.Alignment = 2).

    All the best.

    Chris

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Post

    Thanks for the help

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I obviously have VB6 and not VB5 (my apologies Chris), but I think this would work in VB5. Create a second textbox with the properties you want and at design time set it's Visible property to False. Then in a command button do the following:
    Code:
    Private Sub Command1_Click()
        
        Const LEFT_ALIGN_TB = 0
        Const CENTER_ALIGN_TB = 1
    
        Text1(CENTER_ALIGN_TB).Text = Text1(LEFT_ALIGN_TB).Text
        Text1(CENTER_ALIGN_TB).Top = Text1(LEFT_ALIGN_TB).Top
        Text1(CENTER_ALIGN_TB).Left = Text1(LEFT_ALIGN_TB).Left
        Text1(CENTER_ALIGN_TB).Width = Text1(LEFT_ALIGN_TB).Width
        Text1(CENTER_ALIGN_TB).Height = Text1(LEFT_ALIGN_TB).Height
        Text1(CENTER_ALIGN_TB).Visible = True
        Text1(LEFT_ALIGN_TB).Visible = False
        
    End Sub
    The above uses a TextBox control array. You could adapt it to use seperate TextBoxes if you want to.
    ------------------
    Marty
    Why is it called lipstick if you can still move your lips?


    [This message has been edited by MartinLiss (edited 01-26-2000).]

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I'm sorry, but Chris' statement is not true. You should be able to change the alignment of the text in the textbox at any time, with or without MultiLine set to True. Please post some of your code and perhaps we can find what's wrong.

    ------------------
    Marty
    Why is it called lipstick if you can still move your lips?

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