Results 1 to 36 of 36

Thread: Graphics - Rounded Corners & Drawing [Resolved]

Hybrid View

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Graphics - Rounded Corners

    Ok, I got that to draw but how would I clear the square edges? I just need to
    create a rectangle with the top two corners rounded and then fill it will a
    gradient (I can do the fill part already). The background will be transparent
    by default so when I draw the region and fill it the corners will be gone
    already if the rectangle is rounded on top only.

    This is the area that I need to convert to a region, I think, so it can be filled.

    VB Code:
    1. Function BorderRect() As Rectangle
    2.         Dim rec As Rectangle = Me.cmdClose.ClientRectangle
    3.         Return New Rectangle(1, 1, rec.Width - 3, rec.Height - 3)
    4.     End Function
    5.  
    6.     Private Sub DrawRoundedButtons(ByVal g As Graphics, ByVal p As Pen, ByVal rec As Rectangle, ByVal size As Size)
    7.         Dim oldSmoothingMode As SmoothingMode = g.SmoothingMode
    8.         g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
    9.         'Top line
    10.         g.DrawLine(p, rec.Left + size.Width \ 2, rec.Top, rec.Right - size.Width \ 2, rec.Top)
    11.         'Right top corner
    12.         g.DrawArc(p, rec.Right - size.Width, rec.Top, size.Width, size.Height, 270, 90)
    13.         'Right line
    14.         g.DrawLine(p, rec.Right, rec.Top + size.Height \ 2, rec.Right, rec.Bottom)
    15.         'Bottom line
    16.         g.DrawLine(p, rec.Right, rec.Bottom, rec.Left, rec.Bottom)
    17.         'Left line
    18.         g.DrawLine(p, rec.Left, rec.Bottom, rec.Left, rec.Top + size.Height \ 2)
    19.         'Left top corner
    20.         g.DrawArc(p, rec.Left, rec.Top, size.Width, size.Height, 180, 90)
    21.         g.SmoothingMode = oldSmoothingMode
    22.     End Sub
    23.  
    24.     Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles cmdClose.Paint
    25.         DrawRoundedButtons(e.Graphics, New Pen(Color.Black), BorderRect, New Size(16, 16))
    26.     End Sub
    Thanks
    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 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 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

  2. #2

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Graphics - Rounded Corners

    Ok, I think I may have it. I can get it to draw a region and fill it with a gradient.
    Now I need to see if I can get it to draw on the background of my control
    yet allow the text to be in front. If not then I will need to draw the text
    too.

    Note: this is on a button only as a test (75 x 23)

    VB Code:
    1. Private Sub Button1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
    2.         Dim myPath As New GraphicsPath
    3.         'Top line
    4.         myPath.AddLine(7, 0, 64, 0)
    5.         'Right top arc
    6.         myPath.AddArc(64, 0, 10, 10, 270, 90)
    7.         'Right line
    8.         myPath.AddLine(74, 7, 74, 22)
    9.         'Bottom line
    10.         myPath.AddLine(74, 22, 0, 22)
    11.         'Left line
    12.         myPath.AddLine(0, 22, 0, 7)
    13.         'Left top arc
    14.         myPath.AddArc(0, 0, 10, 10, 180, 90)
    15.         ' Draw the path to the screen.
    16.         Dim myPen As New Pen(Color.White, 1)
    17.         e.Graphics.DrawPath(myPen, myPath)
    18.         'Draw the gradient
    19.         Dim br As New LinearGradientBrush(Me.ClientRectangle, Color.White, Color.CornflowerBlue, LinearGradientMode.Horizontal)
    20.         e.Graphics.FillPath(br, myPath)
    21.     End Sub
    22.  
    23.     Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    24.         Me.Button1.Invalidate()
    25.     End Sub
    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 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 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

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Graphics - Rounded Corners

    So far so good. I am getting around the text by placing a label with a transparent
    background as a child control. Now I have another problem, I need to draw a
    circular button with a gradient border. Sounds like too much work so I want
    to use an image.

    how do I draw an image from a imagelist on my label?
    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 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 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

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Something like this should draw the first picture in the imagelist on a a lable (this is in the paint event handler) :
    VB Code:
    1. [size=2]e.Graphics.DrawImage([/size][size=2][color=#0000ff]Me[/color][/size][size=2].ImageList1.Images(0), [/size][size=2][color=#0000ff]New[/color][/size][size=2] PointF(x, y))[/size]

  5. #5

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Graphics - Rounded Corners & Drawing

    Ok, thanks but I am thinking of making my own control out of this since its
    evolving that way. Would I be able to use an IL on a control or would it be
    better to use the image as a resource?

    Thanks and sorry for the delay. I was remodeling my house all weekend.
    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 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 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

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by RobDog888
    Ok, thanks but I am thinking of making my own control out of this since its
    evolving that way. Would I be able to use an IL on a control or would it be
    better to use the image as a resource?

    Thanks and sorry for the delay. I was remodeling my house all weekend.
    Umm , can you jog my memory on this one "IL" (It wouldn't make sense if I say Intermediate Language , would it? )????

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Graphics - Rounded Corners & Drawing

    Sorry about that. I mean Image List. I think it may be better to use an image as a resource?
    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 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 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width