Results 1 to 10 of 10

Thread: Multiline in TextBox

  1. #1

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Arrow Multiline in TextBox

    Im desion a textbox (usercontrol) im write many properties for it but I could not write multiline property im try to writ it but without result
    I had a problem in ScrollBars Property but I succeeded by using the API

    now the Problem in multiline .. Please help me

    Note: I use a text box tool in the control


    Thanked the author for those who help me
    Last edited by SNIPER.PS; Jun 7th, 2010 at 02:22 AM.

  2. #2
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Multiline in TextBox

    The multiline property is read-only at design time.

    Perhaps you could use two textboxes. One that's default Multiline=True, and one that's not.

  3. #3

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Re: Multiline in TextBox

    tow text box is problem for me
    can we do this property by API like ScrollBars

    thank you

  4. #4
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Multiline in TextBox

    Your usercontrol is based on Textbox control so it is like an "extended" control. There isn't any better solution than what FireXtol suggested since you are basing it on a standard textbox.

    I guess you will also face a problem with .Wrap property?

    The only solution is to have several textboxes with different styles and one local variable of type TextBox. When loading, decide from the flags what textbox you should use and set local variable to reference that textbox. Once done just operate the textbox through the local variable. It goes unsaid that the rest of them will be hidden....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  5. #5
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Multiline in TextBox

    More ways:

    Default multiline = true. On Change, find newline characters and remove them for 'single line' mode.

    Apparently you can also subclass the WM_CREATE message, and at this crucial moment you can use API to change multiline. But don't take my word for it.

  6. #6

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Re: Multiline in TextBox

    thank you very much FireXtol

    give me Example or Code .. Please

    For the second time I repeat my thanks to you

  7. #7
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Multiline in TextBox

    Sure? I'll google that for you.

    Quote Originally Posted by Rick Rothstein from http://www.codenewsgroups.net/group/microsoft.public.vb.general.discussion/topic10420.aspx
    More than likely, this response will not be the one you use; but I'll post
    it in case.<g>

    The code below will allow you to set the maximum number of lines that a
    TextBox can accept. If you want a non-multiline TextBox, simply set the
    MaxLines variable to 1; if you want a multiline TextBox with 10 lines of
    text maximum, set the MaxLines variable to 10. If you are showing
    ScrollBars, they will "activate" if MaxLines is larger than the maximum
    number of visible lines of text the TextBox can display.

    So, you are probably asking, why might this not be what you want? Well, if
    MaxLines is set to 1, then the maximum amount of text the user can type in
    is limited to the width of the TextBox... no sideways scrolling of text for
    the single line condition. Also, the ScrollBars that need to be displayed
    for the multiline condition will remain visible when MaxLines is set to 1
    (although you may be able to play with that using your posted API code).
    And, of course, you need to fix the maximum number of lines that can be
    typed in when in "multiline" mode. If you can live with these restrictions,
    give the example code below a try.

    Rick

    Start a new project. Add a TextBox to the form and set its MultiLine
    property to True and set the ScrollBars to 2-Vertical. Then paste this code
    into the form's code window.
    vb Code:
    1. Dim MaxLines As Long
    2.  
    3. Private Declare Function SendMessageLong Lib _
    4.     "user32" Alias "SendMessageA" _
    5.     (ByVal hwnd As Long, _
    6.      ByVal wMsg As Long, _
    7.      ByVal wParam As Long, _
    8.      ByVal lParam As Long) As Long
    9.  
    10. Const EM_LINEFROMCHAR = &HC9&
    11.  
    12. Private Sub Text1_Change()
    13.   Static LastText As String
    14.   Static LastCaretPos As Long
    15.   Static SecondTime As Boolean
    16.   Dim CurrentCaretPos As Long
    17.   Static NotFirstTime As Boolean
    18.   If NotFirstTime = False Then
    19.     NotFirstTime = True
    20.     Exit Sub
    21.   End If
    22.   With Text1
    23.     If Not SecondTime Then
    24.       CurrentCaretPos = .SelStart
    25.       .SelStart = Len(.Text)
    26.       If SendMessageLong(.hwnd, EM_LINEFROMCHAR, _
    27.                          -1&, 0&) + 1 > MaxLines Then
    28.         Beep
    29.         SecondTime = True
    30.         .Text = LastText
    31.         .SelStart = LastCaretPos
    32.       Else
    33.         LastText = .Text
    34.         .SelStart = CurrentCaretPos
    35.         LastCaretPos = .SelStart
    36.       End If
    37.     End If
    38.   End With
    39.   SecondTime = False
    40. End Sub
    41.  
    42. Private Sub Form_Load()
    43.   ' Here, I am setting MaxLines to 100 lines just to give
    44.   ' the code something to work with initially. You can set
    45.   ' this initial value to whatever you want and, of course,
    46.   ' reset it to any other value (for example, 1 to make it
    47.   ' a single line entry TextBox
    48.   MaxLines = 100
    49. End Sub

  8. #8

    Thread Starter
    Lively Member SNIPER.PS's Avatar
    Join Date
    Dec 2009
    Posts
    96

    Re: Multiline in TextBox

    in normal text can is set mlutiline = true or false by code in any way
    Last edited by SNIPER.PS; Jun 7th, 2010 at 02:14 PM.

  9. #9
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Multiline in TextBox

    Quote Originally Posted by SNIPER.PS View Post
    in normal text can is set mlutiline = true or false by code in any way
    Research subclassing. It's the only way in VB(unless you create the control in another language... but either way you'll be dealing with the same kinds of API).

    I've little experience with subclassing, and I honestly don't know how to do it.

  10. #10
    Fanatic Member DrUnicode's Avatar
    Join Date
    Mar 2008
    Location
    Natal, Brazil
    Posts
    631

    Re: Multiline in TextBox

    See TextBoxEx Control (Free, with sourecode) at:
    http://www.vbaccelerator.com/codelib...t/txtboxex.htm

    It can set MultiLine at runtime. It does this by saving the Text and recreating the control on the fly.

    Requires SsubTmr6.Dll:
    http://www.vbaccelerator.com/home/VB...er/article.asp
    or download just the binary at:
    http://www.vbaccelerator.com/home/VB...Tmr_Binary.asp
    Last edited by DrUnicode; Jun 7th, 2010 at 04:03 PM. Reason: Typo

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