
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