Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Forcing a textbox style

79 views
Skip to first unread message

Guy Cohen

unread,
Sep 16, 2005, 6:27:14 AM9/16/05
to
Hi all,

I use ES_NUMBER/ES_UPPERCASE/ES_LOWERCASE to force the textbox style.
Can it be un-done ?
I tried Call SendMessage(hWnd, EM_UNDO, 0, ByVal 0&) but this did not work.

In general I have a combo with two options "Numbers only" and "Upper case"

When it is set to the first value - the textbox is set to numbers only.
When I set it to the second (meaning - second time I use em_something) it is
not set to upper case and stays as "Numbers only"
I tried to use EM_UNDO before setting it to the desired case but could not.

Please show the correct way :)

TIA
Guy


Ken Halter

unread,
Sep 16, 2005, 10:03:32 AM9/16/05
to
"Guy Cohen" <con...@mediatek.co.il> wrote in message
news:O2zb1Cqu...@TK2MSFTNGP10.phx.gbl...

> Hi all,
>
> I use ES_NUMBER/ES_UPPERCASE/ES_LOWERCASE to force the textbox style.
> Can it be un-done ?

To "turn it off", instead of....

style = style Or ES_NUMBER

use...

style = style And Not ES_NUMBER

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Please keep all discussions in the groups..


Someone

unread,
Sep 16, 2005, 11:08:56 AM9/16/05
to
> I tried Call SendMessage(hWnd, EM_UNDO, 0, ByVal 0&) but this did not
> work.

If you are using "hWnd" alone, then it refers to the Form, use Text1.hWnd
instead. Also, EM_UNDO doesn't undo the last style change. It is equivalent
to pressing Ctrl+z only.

In addition to what Ken suggested, you could turn off all the 3 styles off
before selecting the new one like this:

' Remove the 3 styles first, if you don't know what it was set to before
style = style And Not ES_UPPERCASE
style = style And Not ES_LOWERCASE


style = style And Not ES_NUMBER

' Set the desired style
style = style Or ES_UPPERCASE


"Guy Cohen" <con...@mediatek.co.il> wrote in message
news:O2zb1Cqu...@TK2MSFTNGP10.phx.gbl...

Rick Rothstein [MVP - Visual Basic]

unread,
Sep 16, 2005, 12:32:53 PM9/16/05
to

You have received direct answers to your question, so I won't repeat
them here. However, I wonder if you are aware that using the numbers
only option (ES_NUMBER constant) will NOT stop someone from pasting in
non-numeric text into your TextBox. I have some non-API code available
to handle your options if this revelation turns out to be a problem for
you.

Rick


Randy Birch

unread,
Sep 16, 2005, 11:37:04 PM9/16/05
to
Personally, I do an AND test to see if the bit is set, and if it is do an
XOR to toggle its state.

if style AND ES_NUMBER then
style = style XOR ES_NUMBER
end if

call sendmessage ...

--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------

"Guy Cohen" <con...@mediatek.co.il> wrote in message
news:O2zb1Cqu...@TK2MSFTNGP10.phx.gbl...

: Hi all,

:
:

Guy Cohen

unread,
Sep 16, 2005, 6:37:27 AM9/16/05
to
Well...

I know what I did wrong :)
Logic problem.

Here is the solution:

/////////////////////
Dim L As Long

L = GetWindowLong(hWnd, GWL_STYLE)
If CBool(L And ES_NUMBER) Then
Call SetWindowLong(hWnd, GWL_STYLE, L - ES_NUMBER)
End If
L = GetWindowLong(hWnd, GWL_STYLE)
If CBool(L And ES_UPPERCASE) Then
Call SetWindowLong(hWnd, GWL_STYLE, L - ES_UPPERCASE)
End If
L = GetWindowLong(hWnd, GWL_STYLE)
If CBool(L And ES_LOWERCASE) Then
Call SetWindowLong(hWnd, GWL_STYLE, L - ES_LOWERCASE)
End If

L = GetWindowLong(hWnd, GWL_STYLE)

Select Case venTextStyle
Case enTextStyle.Number
Call SetWindowLong(hWnd, GWL_STYLE, L Or ES_NUMBER)
Case enTextStyle.UpperCase
Call SetWindowLong(hWnd, GWL_STYLE, L Or ES_UPPERCASE)
Case enTextStyle.LowerCase
Call SetWindowLong(hWnd, GWL_STYLE, L Or ES_LOWERCASE)
End Select

/////////////////////

Guy


"Guy Cohen" <con...@mediatek.co.il> wrote in message
news:O2zb1Cqu...@TK2MSFTNGP10.phx.gbl...

0 new messages