Visual Basic Window/Form Routines
Pure VB: Easily Add a Raised or Etched 3D Line Beneath a Menu
     
Posted:   Tuesday March 04, 2003
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB6, Windows XP
OS restrictions:   None
Author:   dnagel, msnews groups
     

Related:  

FillRect: Gradient Form Backgrounds
GradientFill: Gradient Form Backgrounds
GradientFill: Triangular Gradient Form Backgrounds
Pure VB: Tile an Image as a Form Background

     
 Prerequisites
None.

When I create an application containing a menu, I always add two line controls to the form and position them in the resize event such as to create an etched line below the menu. This code uses VB's Line method instead, and when called from the Form_Paint event, guarantees the line will always fill the client area of the form.

For this demo, I've placed the code in command buttons so you can see the difference between the etched and raised look.

 BAS Module Code
None.

 
 Form Code
Add the following code to a form containing two command buttons (Command1, Command2):

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Declare Function GetSysColor Lib "user32" _
   (ByVal nIndex As Long) As Long

Private Const COLOR_BTNFACE = 15
Private Const COLOR_BTNSHADOW = 16


Private Sub Command1_Click()

  'raised
   Me.Line (0, 15)-(ScaleWidth, 15), GetSysColor(COLOR_BTNSHADOW)
   Me.Line (0, 0)-(ScaleWidth, 0), vbWhite
    
End Sub

Private Sub Command2_Click()

  'etched
   Me.Line (0, 15)-(ScaleWidth, 15), vbWhite
   Me.Line (0, 0)-(ScaleWidth, 0), GetSysColor(COLOR_BTNSHADOW)
    
End Sub
 Comments
Once you've chosen a style, use the code to the Form_Paint event to ensure the line is always repainted, regardless of the form resizing. This same technique can also be used to draw 3D lines anywhere on the form.

 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter