Hi,
I would like to know how I can draw a line in a vba form like I can do in VB with the Line control.
Thanks everyone.
Dominic Lavoie
Printable View
Hi,
I would like to know how I can draw a line in a vba form like I can do in VB with the Line control.
Thanks everyone.
Dominic Lavoie
This will work for VB form, but I couldn't get it to work for the UserForm?
Maybe it can help point you in the right direction.
UserForm is missing an .hdc property so this will not completely work for VBA forms.VB Code:
Option Explicit Const HS_DIAGCROSS = 5 Const HS_HORIZONTAL As Long = 0 Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function CreateHatchBrush Lib "gdi32" (ByVal nIndex As Long, ByVal crColor As Long) As Long Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _ ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, _ ByVal nWidth As Long, ByVal nHeight As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _ ByVal Y2 As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long Private Sub Form_Load() Me.ScaleMode = vbPixels End Sub Private Sub Form_Resize() Dim hHBr As Long Dim R As RECT Dim hFRgn As Long 'Set the rectangle's values SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight 'Create a new brush hHBr = CreateHatchBrush(HS_HORIZONTAL, vbRed) 'Draw a rounded rectangle hFRgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, (Me.ScaleWidth / 3) * 2, (Me.ScaleHeight / 3) * 5) 'Draw a frame FrameRgn Me.hdc, hFRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight 'Clean up DeleteObject hFRgn DeleteObject hHBr End Sub
What I want to do is less complicated than the code that you send me. It's in desing time that I want to draw the line, not in runtime.
In vba, what is the equivalent control for VB line
thanks
Ah ha, I found an easy way for you, although a bit half-assed.
Add a label to the userform and set the borderstyle = 1. Then set
the height = 1. Set the bordercolor = black or ???. resize the
label to the width you want and presto - A line ???
well. i always use a label.. with (_) along it.. ;)Quote:
Originally posted by RobDog888
Ah ha, I found an easy way for you, although a bit half-assed.
Add a label to the userform and set the borderstyle = 1. Then set
the height = 1. Set the bordercolor = black or ???.