Draw line in a vba form-VBForums
Results 1 to 5 of 5

Thread: Draw line in a vba form

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Laval, Montréal, Canada
    Posts
    13

    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

  2. #2
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,007
    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:
    1. Option Explicit
    2.  
    3. Const HS_DIAGCROSS = 5
    4. Const HS_HORIZONTAL As Long = 0
    5.  
    6. Private Type RECT
    7.     Left As Long
    8.     Top As Long
    9.     Right As Long
    10.     Bottom As Long
    11. End Type
    12.  
    13. Private Declare Function CreateHatchBrush Lib "gdi32" (ByVal nIndex As Long, ByVal crColor As Long) As Long
    14.  
    15. Private Declare Function CreateRoundRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
    16. ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
    17.  
    18. Private Declare Function FrameRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long, _
    19. ByVal nWidth As Long, ByVal nHeight As Long) As Long
    20.  
    21. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    22.  
    23. Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, _
    24. ByVal Y2 As Long) As Long
    25.  
    26. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    27.  
    28. Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
    29.  
    30. Private Sub Form_Load()
    31.     Me.ScaleMode = vbPixels
    32. End Sub
    33.  
    34. Private Sub Form_Resize()
    35.    
    36.     Dim hHBr As Long
    37.     Dim R As RECT
    38.     Dim hFRgn As Long
    39.  
    40.     'Set the rectangle's values
    41.     SetRect R, 0, 0, Me.ScaleWidth, Me.ScaleHeight
    42.     'Create a new brush
    43.     hHBr = CreateHatchBrush(HS_HORIZONTAL, vbRed)
    44.     'Draw a rounded rectangle
    45.     hFRgn = CreateRoundRectRgn(0, 0, Me.ScaleWidth, Me.ScaleHeight, (Me.ScaleWidth / 3) * 2, (Me.ScaleHeight / 3) * 5)
    46.     'Draw a frame
    47.     FrameRgn Me.hdc, hFRgn, hHBr, Me.ScaleWidth, Me.ScaleHeight
    48.     'Clean up
    49.     DeleteObject hFRgn
    50.     DeleteObject hHBr
    51.  
    52. 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!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Location
    Laval, Montréal, Canada
    Posts
    13

    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

  4. #4
    Super Moderator RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,007
    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!
    Star Wars Gangsta Rap Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel Core 2 Extreme Ed., 2 WD Raptor 10K RPM 300 GB HDs, 2 GBs DDR2 667 MHz RAM, 2 Viewsonic 24" LCDs, Windows 7 SP-1/Windows 8.1, Office 2010, VS 2013

  5. #5
    Lively Member amer7862000's Avatar
    Join Date
    Apr 2004
    Location
    North West, UK
    Posts
    94
    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.