
Set Borderstyle and Apperance of a TextBox runtime.
This seems to work, although you may prefer to save the GetXX style to a variable....
Const WS_EX_CLIENTEDGE = &H200&
Const GWL_EXSTYLE = (-20)
Private Sub Text1_GotFocus()
Dim rStyle As Long
Dim r As Long
rStyle = GetWindowLong(Text1.hwnd, GWL_EXSTYLE)
If rStyle And Not WS_EX_CLIENTEDGE Then
rStyle = rStyle Xor WS_EX_CLIENTEDGE
r = SetWindowLong(Text1.hwnd, GWL_EXSTYLE, rStyle)
r = SetWindowPos(Text1.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End If
End Sub
Private Sub Text1_LostFocus()
Dim rStyle As Long
Dim r As Long
rStyle = GetWindowLong(Text1.hwnd, GWL_EXSTYLE)
If rStyle And WS_EX_CLIENTEDGE Then
rStyle = rStyle Xor WS_EX_CLIENTEDGE
r = SetWindowLong(Text1.hwnd, GWL_EXSTYLE, rStyle)
r = SetWindowPos(Text1.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End If
End Sub
The constants and APIs are in the API viewer. Tested on VB5/Win95.
--
Randy Birch, MVP Visual Basic
VBnet, The Visual Basic Developers Resource Centre
http://home.sprynet.com/sprynet/rasanen/vbnet/default.htm
:Gofreddo's answer is good, but there's another type of trick you can use.
:
:A 3D picturebox has a borderstyle property that makes it appear flat if set
:to none. So put your textbox (appearance = flat) inside a picturebox
:(appearance = 3D) and just change the picturebox's borderstyle. Cute, eh?
:
:Here's the complete code (just be sure you place text1 _inside_ picture1)
:
:Private Sub Command1_Click()
: If Picture1.BorderStyle = 0 Then
: Picture1.BorderStyle = 1
: Text1.Left = -Screen.TwipsPerPixelX
: Text1.Top = -Screen.TwipsPerPixelY
: Else
: Picture1.BorderStyle = 0
: Text1.Left = 0
: Text1.Top = 0
: End If
:End Sub
:
:Private Sub Form_Load()
: Picture1.Width = Text1.Width
: Picture1.Height = Text1.Height
:End Sub
:
:Jim Deutch
:MS Dev MVP
:
:> The header says it all I guess.
:> I'd like to set the borderstyle and apperance of a TextBux at runtime.
:>
:>
:> Any help appreciated.
:>
:> Roy Magne Indreb?
:>
:>
:>