Default button causing problem for multi-line textbox 
Author Message
 Default button causing problem for multi-line textbox

I have a dialog with a multi-line textbox and a Command button that has its
Default property set making it the Default control on the form.

Problem is, when the textbox has focus and the user presses enter, the
command button click event is being executed instead of creating a new line
in the textbox.

I know the standard is to use CTRL+Enter to take a new line in this
situation but that's not what I want to do in this case.

I also know that in theory I should be able to use the SetWindowLong API
with the ES_WANTRETURN style to change this behaviour to what I want but I
haven't been able to get it to work and I can't see what I'm doing wrong.
Can anyone provide me with some sample code that works? The following
demonstrates what I'm currently doing:

Private Sub Form_Load()
    Dim lngStyle As Long

    lngStyle = GetWindowLong(Text1.hWnd, GWL_STYLE)
    lngStyle = lngStyle Or ES_WANTRETURN
    Call SetWindowLong(Text1.hWnd, GWL_STYLE, lngStyle)

End Sub

And I don't want to set the button's default property to False unless
there's absolutely no other way to do it

Regards,

Gary



Sat, 10 Apr 2004 00:07:28 GMT  
 Default button causing problem for multi-line textbox
Hi Gary,

I think your approach will not work because you are trying to configure the
textbox to behave differently.  Actually, when the user presses Enter this
key will not be sent to textbox because the application consumes it and
generates a click event for the default button.
In my opinion, there is no way to get this behavior with a default button on
the form.

Hamilton



Quote:
> I have a dialog with a multi-line textbox and a Command button that has
its
> Default property set making it the Default control on the form.

> Problem is, when the textbox has focus and the user presses enter, the
> command button click event is being executed instead of creating a new
line
> in the textbox.

> I know the standard is to use CTRL+Enter to take a new line in this
> situation but that's not what I want to do in this case.

> I also know that in theory I should be able to use the SetWindowLong API
> with the ES_WANTRETURN style to change this behaviour to what I want but I
> haven't been able to get it to work and I can't see what I'm doing wrong.
> Can anyone provide me with some sample code that works? The following
> demonstrates what I'm currently doing:

> Private Sub Form_Load()
>     Dim lngStyle As Long

>     lngStyle = GetWindowLong(Text1.hWnd, GWL_STYLE)
>     lngStyle = lngStyle Or ES_WANTRETURN
>     Call SetWindowLong(Text1.hWnd, GWL_STYLE, lngStyle)

> End Sub

> And I don't want to set the button's default property to False unless
> there's absolutely no other way to do it

> Regards,

> Gary



Sat, 10 Apr 2004 00:40:42 GMT  
 Default button causing problem for multi-line textbox

Don't think this is very elegant, but why not set Command1.Default = False
in the got focus of the textbox control and Command1.Default = True in the
lost focus?

Bruce H


Quote:
> I have a dialog with a multi-line textbox and a Command button that has
its
> Default property set making it the Default control on the form.

> Problem is, when the textbox has focus and the user presses enter, the
> command button click event is being executed instead of creating a new
line
> in the textbox.

> I know the standard is to use CTRL+Enter to take a new line in this
> situation but that's not what I want to do in this case.

> I also know that in theory I should be able to use the SetWindowLong API
> with the ES_WANTRETURN style to change this behaviour to what I want but I
> haven't been able to get it to work and I can't see what I'm doing wrong.
> Can anyone provide me with some sample code that works? The following
> demonstrates what I'm currently doing:

> Private Sub Form_Load()
>     Dim lngStyle As Long

>     lngStyle = GetWindowLong(Text1.hWnd, GWL_STYLE)
>     lngStyle = lngStyle Or ES_WANTRETURN
>     Call SetWindowLong(Text1.hWnd, GWL_STYLE, lngStyle)

> End Sub

> And I don't want to set the button's default property to False unless
> there's absolutely no other way to do it

> Regards,

> Gary



Sat, 10 Apr 2004 02:16:26 GMT  
 Default button causing problem for multi-line textbox

Quote:
> Don't think this is very elegant, but why not set Command1.Default = False
> in the got focus of the textbox control and Command1.Default = True in the
> lost focus?

I've used this method myself and it works well.

Elegant? In the absense of any other solution...who cares? :)

Rob :)



Sat, 10 Apr 2004 20:15:21 GMT  
 Default button causing problem for multi-line textbox
Why not keep Default = false at all times, set keypreview = true on the
form, and when the active control is the textbox, then make Ctrl-Enter be
the default button (sense the key, and call the click event of the button)
and when in all other controls, make just Enter be the default.  Or make
ctrl-enter default for the entire form (defeats the purpose though)

Anthony


Quote:
> I have a dialog with a multi-line textbox and a Command button that has
its
> Default property set making it the Default control on the form.

> Problem is, when the textbox has focus and the user presses enter, the
> command button click event is being executed instead of creating a new
line
> in the textbox.

> I know the standard is to use CTRL+Enter to take a new line in this
> situation but that's not what I want to do in this case.

> I also know that in theory I should be able to use the SetWindowLong API
> with the ES_WANTRETURN style to change this behaviour to what I want but I
> haven't been able to get it to work and I can't see what I'm doing wrong.
> Can anyone provide me with some sample code that works? The following
> demonstrates what I'm currently doing:

> Private Sub Form_Load()
>     Dim lngStyle As Long

>     lngStyle = GetWindowLong(Text1.hWnd, GWL_STYLE)
>     lngStyle = lngStyle Or ES_WANTRETURN
>     Call SetWindowLong(Text1.hWnd, GWL_STYLE, lngStyle)

> End Sub

> And I don't want to set the button's default property to False unless
> there's absolutely no other way to do it

> Regards,

> Gary



Sat, 10 Apr 2004 20:50:54 GMT  
 Default button causing problem for multi-line textbox
That would work Anthony, but it would leave the default button without the
bold border drawn around it (a Windows UI standard), and could confuse the
user. It would also be slightly more resource intensive.

Bruce H


Quote:
> Why not keep Default = false at all times, set keypreview = true on the
> form, and when the active control is the textbox, then make Ctrl-Enter be
> the default button (sense the key, and call the click event of the button)
> and when in all other controls, make just Enter be the default.  Or make
> ctrl-enter default for the entire form (defeats the purpose though)

> Anthony



> > I have a dialog with a multi-line textbox and a Command button that has
> its
> > Default property set making it the Default control on the form.

> > Problem is, when the textbox has focus and the user presses enter, the
> > command button click event is being executed instead of creating a new
> line
> > in the textbox.

> > I know the standard is to use CTRL+Enter to take a new line in this
> > situation but that's not what I want to do in this case.

> > I also know that in theory I should be able to use the SetWindowLong API
> > with the ES_WANTRETURN style to change this behaviour to what I want but
I
> > haven't been able to get it to work and I can't see what I'm doing
wrong.
> > Can anyone provide me with some sample code that works? The following
> > demonstrates what I'm currently doing:

> > Private Sub Form_Load()
> >     Dim lngStyle As Long

> >     lngStyle = GetWindowLong(Text1.hWnd, GWL_STYLE)
> >     lngStyle = lngStyle Or ES_WANTRETURN
> >     Call SetWindowLong(Text1.hWnd, GWL_STYLE, lngStyle)

> > End Sub

> > And I don't want to set the button's default property to False unless
> > there's absolutely no other way to do it

> > Regards,

> > Gary



Sat, 24 Apr 2004 03:06:43 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Multiline Textbox Cause Page Overflows when Printing or doesn't print all lines

2. Multiline textbox and default button conflicting

3. Multiline textbox and Default button conflicting

4. VB 5:ListView causes problems with Default button

5. Problem with Multi-Line Textbox

6. TextBox -- Multi-Line & Problem with Back Color

7. Read a MultiLine textbox line by line?

8. Limit a multi-line textbox to 10 lines ?

9. Limitting line length of each line within multiline textbox

10. No of lines in a multi line TextBox ?

11. Multi-line textbox

12. Positon of cursor in multi-line textbox

 

 
Powered by phpBB® Forum Software