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

Option ExplicitPrivate Type RECT    Left As Long    Top As Long    Right As Long    Bottom As LongEnd TypePrivate Enum mbBorderTypeConstants    mbRaised = 0    mbSunken = 1    mbEtched = 2    mbBump = 3End Enum'draw a raised/bump/etched/sunken border at given coordinatesPrivate 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 = iOldDrawWidthEnd Sub'samplePrivate 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, 2End Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS