Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB
Expertise: Intermediate
Jan 25, 2006

Using a Default Button and a Multiline Text Box on the Same Form

Suppose you have a button that uses a Default property (set to true) and are editing text in a multiline text box on the same form. When you press the enter, the button's click event fires rather than having a new line added to the text box.

Placing the following code into your click event on the default button on your form enables you to use a default button and a multiline text box on the same form. Basically, this code checks which control has the focus—if it's a multiline textbox, the code cancels the button's click event. You then have to send a newline to the text box manually.


Private Sub cmdOK_Click()
    Static ignoreClick As Boolean
    
    If ignoreClick = False Then
        If TypeOf ActiveControl Is TextBox Then
            If ActiveControl.MultiLine = True Then
                SendKeys vbCrLf
                ignoreClick = True
                Exit Sub
            End If
        End If
    Else
        ignoreClick = False
        Exit Sub
    End If
    
    ' normal code for the OK button would go here...

End Sub
Valpied Adam
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap