Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Etched Border 1

Status
Not open for further replies.

bmcc

Technical User
May 31, 2002
10
US
I used Shape control to draw a rectangle on a form. How can I change the border of this rectangle to be etched? or inverted, or sunken? Many thanks.
 
The standard shape controls do not have this capability. You need to explore the DrawEdge API function which can draw a variety of borders.

You can draw on the form or picture box. Or you can write a small user control if you are going to use it frequently.

See the example here. The following code goes in the form.
___
[tt]
Private Declare Function DrawEdge Lib "user32" (ByVal hdc As Long, qrc As RECT, ByVal Edge As Long, ByVal grfFlags As Long) As Long
Const BF_RECT = 15
Enum Borders
RaisedSingle = 1
RaisedDouble = 5
SunkenSingle = 2
SunkenDouble = 10
Bump = 9
Etched = 6
End Enum
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long
Const DT_VCENTER = &H4
Const DT_CENTER = &H1
Const DT_SINGLELINE = &H20

Private Sub Form_Load()
WindowState = vbMaximized
AutoRedraw = True
Dim rc As RECT
rc.Left = 100
rc.Right = 200
Dim N As Long

rc.Top = 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Raised Single", RaisedSingle, rc

rc.Top = rc.Top + 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Raised Double", RaisedDouble, rc

rc.Top = rc.Top + 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Sunken Single", SunkenSingle, rc

rc.Top = rc.Top + 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Sunken Double", SunkenDouble, rc

rc.Top = rc.Top + 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Etched", Etched, rc

rc.Top = rc.Top + 50
rc.Bottom = rc.Top + 30
DrawTextInRect "Bump", Bump, rc
End Sub

Private Sub DrawTextInRect(Text As String, Edge As Borders, rc As RECT)
DrawEdge hdc, rc, Edge, BF_RECT
DrawText hdc, Text, Len(Text), rc, DT_CENTER Or DT_VCENTER Or DT_SINGLELINE
End Sub[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top