-
Apr 5th, 2004, 10:08 AM
#1
Thread Starter
New Member
Draw line in a vba form
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
-
Apr 5th, 2004, 10:55 AM
#2
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.
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
UserForm is missing an .hdc property so this will not completely work for VBA forms.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 5th, 2004, 12:15 PM
#3
Thread Starter
New Member
In design time
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
-
Apr 5th, 2004, 12:27 PM
#4
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 ???
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 12th, 2004, 07:49 PM
#5
Lively Member
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 ???.
well. i always use a label.. with (_) along it..
"Through every dark night there's a brighter day, so no matter how hard it get, put your chest out and keep your head up, and handle it"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|