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
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 iOldScaleMode = Target.ScaleMode iOldDrawWidth = Target.DrawWidth TPPX = Screen.TwipsPerPixelX TPPY = Screen.TwipsPerPixelY rc.Left = rcBorder.Left * TPPX rc.Right = rcBorder.Right * TPPX rc.Top = rcBorder.Top * TPPY rc.Bottom = rcBorder.Bottom * TPPY 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 Target.ScaleMode = iOldScaleMode Target.DrawWidth = iOldDrawWidth End Sub
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 |