[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3128
  • Last Modified:

move to next line in text box vb6

I have a text box in vb6 and I set the multiline property to true.  When I type a sentence in the textbox and then want to go to a new line, how is that possible?  It seems that I have to press spacebar until I get to the next line.
0
al4629740
Asked:
al4629740
  • 4
  • 3
  • 3
  • +2
1 Solution
 
KorbusCommented:
What does the "enter" key do?  Take you to the next field?
Usually, the enter key should take you to the next line (in a multi-line enabled text box).
0
 
al4629740Author Commented:
Ahh,

I have the default set on a command button within the same screen.  I guess the two cannot coexist...
0
 
KorbusCommented:
No way, that would be awful!  I'm going to test that right now myself, I'll let you know if I get the same.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
KorbusCommented:
Confirmed:  With "Accept Button" specified in the form properties, the enter key no longer works in the multi-line text box.   Pretty poor IMO.

Here is a possible workaround (untested):
In the text box's "gotfocus" event: you can change the accept button on the form properties to nothing,  then on "lostfocus", change the form's accept button property back to  your button.

(Pretty sure I used the wrong names for those focus events, but hopefully you see what I mean.)
0
 
Martin LissOlder than dirtCommented:
If you want to type in a new line you could just add a command button with this code.

Text1.Text = Text1.Text & vbCrLf

If instead you want to continue the current line then do this

Text1.SelStart = Len(Text1.Text)
0
 
al4629740Author Commented:
Boy.  Seems like an extra annoying step...

Thanks guys
0
 
Martin LissOlder than dirtCommented:
In defense of VB6, it really doesn't know that you want to add a new line rather than adding something at the start or the middle.
0
 
GrahamSkanRetiredCommented:
You say 'sentence', so how does this suit?
Option Explicit

Private Sub Text1_Change()
    Select Case Right(Text1.Text, 1)
        Case ".", "!", "?"
            Text1.Text = Text1.Text & vbCrLf
            Text1.SelStart = Len(Text1.Text)
    End Select
End Sub

Open in new window

0
 
al4629740Author Commented:
Graham

That's a great solution but a little too specific to punctuation
0
 
Martin LissOlder than dirtCommented:
How about this?

Private Sub Text1_LostFocus()
If Right(Text1.Text, 2) = vbCrLf Then
    Exit Sub
Else
    Text1.Text = Text1.Text & vbCrLf
End If
End Sub

Open in new window

0
 
ArkCommented:
Assuming TextBox name is Text1 and default button is Command1:
Private Sub Command1_Click()
    Static ignoreClick As Boolean
    If ignoreClick = False Then
        If Me.ActiveControl Is Text1 Then
           SendKeys vbCrLf
           ignoreClick = True
           Exit Sub
        End If
    Else
        ignoreClick = False
        Exit Sub
    End If
    
    ' your code for default button clicked/enter pressed

End Sub

Open in new window

0
 
ArkCommented:
Improved a bit - keeps Enter behavior for all multiline textboxes if default button (name=Command1) presents:
Private Sub Command1_Click()
    Static ignoreClick As Boolean
    If ignoreClick Then 'fired by SendKeys
       ignoreClick = False
       Exit Sub
    Else
       Dim ctrl As Control
       Set ctrl = Me.ActiveControl
       If TypeOf ctrl Is TextBox Then
          If ctrl.MultiLine = True Then 'enter was pressed in multiline textbox
             SendKeys vbCrLf
             ignoreClick = True
             Exit Sub
          End If
       End If
    End If
    ' your code for default button clicked/enter pressed
    MsgBox "Pressed"
End Sub

Open in new window

0
 
al4629740Author Commented:
Thats exactly what I am looking for.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now