Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COLORIZE frame border , possible?

sal21

Programmer
Apr 26, 2004
448
IT
COLORIZE frame border , possible?
 
No, for some reason you've been provided with an Access solution.

Ok, so ... the VB6 Frame control does not expose any sort of frame border colour property. Nor is there a convenient Windows message we can use. here's a couple of relatively simple solutions (the second is slightly more complex, but also slightly more resilient). I'd explain what they are doing, but you don't ever seem to care much for that sort of thing. Both ideas require a form with a frame and a label

Rich (BB code):
Private Sub Form_Load()
    Dim oldmode As Long
    
    oldmode = Form1.ScaleMode
    Form1.ScaleMode = vbPixels
    Label1.BackStyle = 1 'opaque
    Label1.BackColor = vbRed
    Label1.BorderStyle = 0 ' None
    Label1.Move Frame1.Left - 1, Frame1.Top - 1, Frame1.Width + 2, Frame1.Height + 2
    Label1.ZOrder 0 ' Send to back
    Form1.ScaleMode = oldmode
End Sub

And the second one

Rich (BB code):
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long


Private Sub DrawFrameBorder()
    Dim oldcolor As Long
    Dim oldmode As Long
    Dim hdc As Long
    
    oldmode = Form1.ScaleMode
    oldcolour = Form1.ForeColor


    hdc = GetDC(Me.hwnd) ' Get device context
    Form1.ForeColor = vbRed
    Rectangle hdc, Frame1.Left - 1, Frame1.Top - 1, Frame1.Left + Frame1.Width + 2, Frame1.Top + Frame1.Height + 3
    ReleaseDC Me.hwnd, hdc ' Release device context
    Form1.ForeColor = oldcolour
    Form1.ScaleMode = oldmode
End Sub


Private Sub Form_Paint()
    DrawFrameBorder
End Sub
 

Part and Inventory Search

Sponsor

Back
Top