Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

DrawBorder - Draw a raised/bump/etched/sunken border

Total Hit ( 2371)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
Option Explicit

Private Type RECT
  Left As Long
  Top As Long
  Right As Long
  Bottom As Long
End Type

Private Enum mbBorderTypeConstants
  mbRaised = 0
  mbSunken = 1
  mbEtched = 2
  mbBump = 3
End Enum

'draw a raised/bump/etched/sunken border at given coordinates

Private Sub DrawBorder(Target As Object, rcBorder As RECT, _
  Optional ByVal BorderType As mbBorderTypeConstants = mbRaised, _
  Optional ByVal BorderWidth As Long = 1, Optional ByVal HighLightColor As _
  OLE_COLOR = vb3DHighlight, Optional ByVal ShadowColor As OLE_COLOR = _
  vb3DShadow)
  
  Dim HOffset As Long, VOffset As Long
  Dim iOldScaleMode As Integer, iOldDrawWidth As Integer
  Dim TPPX As Long, TPPY As Long, i As Integer
  Dim rc As RECT
  
  On Error Resume Next
  'save the current target's ScaleMode and DrawWidth
  iOldScaleMode = Target.ScaleMode
  iOldDrawWidth = Target.DrawWidth
  'save the values to convert from pixels to twips
  TPPX = Screen.TwipsPerPixelX
  TPPY = Screen.TwipsPerPixelY
  'convert rect coords from pixels to twips
  rc.Left = rcBorder.Left * TPPX
  rc.Right = rcBorder.Right * TPPX
  rc.Top = rcBorder.Top * TPPY
  rc.Bottom = rcBorder.Bottom * TPPY
  'change the target's ScaleMode (vbTwips) and DrawWidth
  Target.ScaleMode = vbTwips
  Target.DrawWidth = BorderWidth

  Select Case BorderType
    Case Is = mbRaised, mbSunken
      Target.DrawWidth = 1
      For i = 1 To BorderWidth
        Target.Line (rc.Left + HOffset, rc.Top + VOffset)-(rc.Left + _
          HOffset, rc.Bottom - VOffset), IIf(BorderType = mbRaised, _
          HighLightColor, ShadowColor)
        Target.Line (rc.Left + HOffset, rc.Top + VOffset)-(rc.Right - _
          HOffset, rc.Top + VOffset), IIf(BorderType = mbRaised, _
          HighLightColor, ShadowColor)
        Target.Line (rc.Right - HOffset - TPPX, _
          rc.Top + VOffset)-(rc.Right - HOffset - TPPX, _
          rc.Bottom - VOffset), IIf(BorderType = mbRaised, _
          ShadowColor, HighLightColor)
        Target.Line (rc.Left + HOffset, rc.Bottom - VOffset - TPPY)- _
          (rc.Right - HOffset, rc.Bottom - VOffset - TPPY), _
          IIf(BorderType = mbRaised, ShadowColor, HighLightColor)
        HOffset = HOffset + TPPX
        VOffset = VOffset + TPPY
      Next
      
    Case Is = mbEtched, mbBump
      HOffset = -Int(-(BorderWidth / 2)) * TPPX
      VOffset = -Int(-(BorderWidth / 2)) * TPPY
      If BorderWidth = 1 Then
        TPPX = 0
        TPPY = 0
      End If
      Target.Line (rc.Left + HOffset + TPPX, rc.Top + VOffset + TPPY)- _
        (rc.Right - HOffset, rc.Bottom - VOffset), _
        IIf(BorderType = mbEtched, HighLightColor, ShadowColor), B
      Target.Line (rc.Left + TPPX, rc.Top + TPPY)-(rc.Right - 2 * HOffset, _
        rc.Bottom - 2 * VOffset), IIf(BorderType = mbEtched, _
        ShadowColor, HighLightColor), B
  End Select
  'restore the old values for the target's ScaleMode and ScaleWidth properties
  Target.ScaleMode = iOldScaleMode
  Target.DrawWidth = iOldDrawWidth
End Sub


'sample
Private Sub Form_Load()
  Dim rc As RECT
  rc.Left = 10
  rc.Top = 10
  rc.Bottom = 110
  rc.Right = 110
  DrawBorder Me, rc, mbRaised, 2
  rc.Left = 20
  rc.Top = 20
  rc.Bottom = 100
  rc.Right = 100
  DrawBorder Me, rc, mbSunken, 2
  
  rc.Left = 150
  rc.Top = 10
  rc.Bottom = 110
  rc.Right = 250
  DrawBorder Me, rc, mbEtched, 2
  rc.Left = 160
  rc.Top = 20
  rc.Bottom = 100
  rc.Right = 240
  DrawBorder Me, rc, mbBump, 2
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.