Results 1 to 7 of 7

Thread: Making a 'Word wrap' button in VB

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    15

    Post Making a 'Word wrap' button in VB

    I'm looking to make a word wrap menu item on my Windows Form Application, much (exactly) like the Word wrap button on Notepad. I basically want a button to 'wrap' (automatically start a new line of text when getting to the end of the textbox) and 'unwrap' (line continues when it reaches the end of the text box).
    Attached Images Attached Images  
    Last edited by JakeC; Apr 20th, 2021 at 01:50 PM.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Making a 'Word wrap' button in VB

    Have you consulted the documentation on the WordWrap property: https://docs.microsoft.com/en-us/dot...xbase.wordwrap

    The TextBox's Multiline property must be true, but you can toggle the WordWrap property to turn it off an on.

    One option is to use a CheckBox control, set the appearance to Button, then in the CheckChange event use the following code:
    Code:
    Private Sub CheckBoxWordWrap_CheckChanged(sender As Object, e As EventArgs) Handles CheckBoxWordWrap.CheckChanged
        MyTextBox.WordWrap = CheckBoxWordWrap.Checked
    End Sub
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    15

    Re: Making a 'Word wrap' button in VB

    Thank you for your answer, but apologies - I meant making word wrap a menu item like on Notepad, not a button.
    Attached Images Attached Images  
    Last edited by JakeC; Apr 20th, 2021 at 01:56 PM.

  4. #4
    Fanatic Member Delaney's Avatar
    Join Date
    Nov 2019
    Location
    Paris, France
    Posts
    845

    Re: Making a 'Word wrap' button in VB

    You can use the menustrip control :https://docs.microsoft.com/fr-fr/dot...p?view=net-5.0

    you can find it in the designer tool box tag : menu and tools bar (or something like that)
    The best friend of any programmer is a search engine
    "Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
    “They did not know it was impossible so they did it” (Mark Twain)

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,715

    Re: Making a 'Word wrap' button in VB

    The property stays the same, even the Checked property stays the same. You can use the exact code that I provided you, swap out CheckBoxWordWrap with the name of your MenuItem, and set the CheckOnClick property of the MenuItem to true.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    15

    Re: Making a 'Word wrap' button in VB

    Ah great, thank you for your help!

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    15

    Re: Making a 'Word wrap' button in VB

    Thank you!

Tags for this Thread

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