Set Borderstyle and Apperance of a TextBox runtime. 
Author Message
 Set Borderstyle and Apperance of a TextBox runtime.

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?



Fri, 11 Aug 2000 03:00:00 GMT  
 Set Borderstyle and Apperance of a TextBox runtime.

Quote:

> 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?

The numeric value of the borderstyle can be retrieved with
"text1.borderstyle", and the appearance with "text1.appearance".  These
will return an integer describing the current setting.  If you want a
textual description then you'll have to build a little array or select
case statement to display the appropriate text to go with the setting.

Do you want a little code snippet to help you out?  If so then reply to

--
<<<<<<<<<<>>>>>>>>>>
Randy Mennie
CompuCall Enterprises
Port Moody, BC, Canada



Fri, 11 Aug 2000 03:00:00 GMT  
 Set Borderstyle and Apperance of a TextBox runtime.

Quote:

> 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?

Private Sub Form_Load()
  Text1.BorderStyle = 1 'Check BorderStyle help for list of VB constants
  Text1.Appearance = 1  'Same here.
End Sub

--
<<<<<<<<<<>>>>>>>>>>
Randy Mennie
CompuCall Enterprises
Port Moody, BC, Canada



Fri, 11 Aug 2000 03:00:00 GMT  
 Set Borderstyle and Apperance of a TextBox runtime.

Since you cant do it at runtime using anything I know about, what I usually
do is to create 2 textboxes.  One with no border and on with a border.  For
instance, I sometimes want to have a form with textboxes with no borders
until the user clicks on one.  That way, the textbox has a pop-down effect
when it gets focus.  To implement this, I make all of my no-border textboxes
in an array and put them where they are supposed to go.  Then I make another
array of border-textboxes and put them wherever and make them invisible.
When the form loads, I run through all elements in the array, moving the
border ones to the same position and size as the non-border ones.  Whenever
a non-border one gets focus, I immediately make the border one visible and
setfocus to it.  Sorry I don't know a better way to do it.  Hope this gives
you some ideas though.
-GMG

Quote:

>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?



Fri, 11 Aug 2000 03:00:00 GMT  
 Set Borderstyle and Apperance of a TextBox runtime.

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



Quote:
> 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?



Sat, 12 Aug 2000 03:00:00 GMT  
 Set Borderstyle and Apperance of a TextBox runtime.

I admit, that is probably the *better* answer.  However, the reason I don't
like to do that is because when you put the textbox in the picturebox, it is
hard as hell to move around on the form.  But, it works : )
Also, aren't picture boxes supposed to consume more resources?  I always try
to minimize my use of them when not necessary.
-GMG


Quote:
>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?



Sat, 12 Aug 2000 03:00:00 GMT  
 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?
:>
:>
:>



Sat, 12 Aug 2000 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Changing borderstyle and apperance

2. Set value of textbox on report at runtime?

3. Set font name in UserControl TextBox at Runtime

4. HELP: Setting scroll bars for TextBox at runtime

5. Setting HideSelection in a TextBox at runtime?

6. TextBox BorderStyle

7. TextBox .BorderStyle property at run-time

8. Changing a Forms BorderStyle as runtime.

9. Changing borderstyle of text box at runtime?

10. Changing Form.Borderstyle - Runtime, using VB3

11. Change borderstyle in runtime????

12. Borderstyle in runtime?

 

 
Powered by phpBB® Forum Software