Visual Basic Tip: 01/01/96


Apply a 3D look to controls (No VBX's/DLL's/API's needed).
Apply a 3D look to controls (No VBX's/DLL's/API's needed).

HAPPY NEW YEAR!

Add the following subroutine to your project (global module):


Sub ThreeDControl (Ctrl As Control, nBevel%, nSpace%, bInset%)
 'Want a 3D look for your application and save system resources?
 'Use this subroutine to apply a 3D look to controls.  No VBX's,
 '  DLL's, or API calls needed!
 '
 'Makes the passed control appear 3D.
 'Ex  : ThreeDControl Text1, 1, 0, True
 '
 'Looks best when background of form or container is light gray.
 '
 'Parameters:
 ' Ctrl    = apply 3D look to control name
 ' nBevel% = bevel width (pixels)
 ' nSpace% = surround distance from control (pixels)
 ' bInset% = True is 3D inset border
 '           False is 3D outset border

 PixX% = Screen.TwipsPerPixelX
 PixY% = Screen.TwipsPerPixelY

 CTop% = Ctrl.Top - PixX%
 CLft% = Ctrl.Left - PixY%
 CRgt% = Ctrl.Left + Ctrl.Width
 CBtm% = Ctrl.Top + Ctrl.Height

' Color used below:
' dark gray = &H808080
' white = &HFFFFFF

 If bInset% Then         'inset border
  For i% = nSpace% To (nBevel% + nSpace% - 1)
   AddX% = i% * PixX%
   AddY% = i% * PixY%
   Ctrl.Parent.Line (CLft% - AddX%, CTop% - AddY%)-(CRgt% + AddX%, CTop% - AddY%), &H808080
   Ctrl.Parent.Line (CLft% - AddX%, CTop% - AddY%)-(CLft% - AddX%, CBtm% + AddY%), &H808080
   Ctrl.Parent.Line (CLft% - AddX%, CBtm% + AddY%)-(CRgt% + AddX% + PixX%, CBtm% + AddY%), &HFFFFFF
   Ctrl.Parent.Line (CRgt% + AddX%, CTop% - AddY%)-(CRgt% + AddX%, CBtm% + AddY%), &HFFFFFF
  Next
 Else                    'outset border
  For i% = nSpace% To (nBevel% + nSpace% - 1)
   AddX% = i% * PixX%
   AddY% = i% * PixY%
   Ctrl.Parent.Line (CRgt% + AddX%, CBtm% + AddY%)-(CRgt% + AddX%, CTop% - AddY%), &H808080
   Ctrl.Parent.Line (CRgt% + AddX%, CBtm% + AddY%)-(CLft% - AddX%, CBtm% + AddY%), &H808080
   Ctrl.Parent.Line (CRgt% + AddX%, CTop% - AddY%)-(CLft% - AddX% - PixX%, CTop% - AddY%), &HFFFFFF
   Ctrl.Parent.Line (CLft% - AddX%, CBtm% + AddY%)-(CLft% - AddX%, CTop% - AddY%), &HFFFFFF
  Next
 End If

End Sub

Return to Phil's Web Page

Created by: Philip