Results 1 to 36 of 36

Thread: Graphics - Rounded Corners & Drawing [Resolved]

  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

    Resolved Graphics - Rounded Corners & Drawing [Resolved]

    Ok, I learned how to do some gradient drawing and now its time to learn how
    to draw arcs. I went through the clock demo in the 101 .NET tutorial projects
    but its a little advanced for me.

    How do I draw an arc, more importantly rounded corners on a control?

    Thanks in advance for any help.
    Last edited by RobDog888; Jan 28th, 2005 at 10:10 PM.
    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, so far I can draw the arcs where I need them, but this will not be good
    unless I can clear the area to make the rounded corners. This is what I have
    so far.

    VB Code:
    1. Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    2.         'Set background to white
    3.         e.Graphics.FillRectangle(Brushes.White, Me.ClientRectangle)
    4.         'Create pen.
    5.         Dim BlackPen As New Pen(Color.Black, 1)
    6.         'Create left rectangle to bound ellipse.
    7.         Dim rLeft As New Rectangle(0, 0, 15, 15)
    8.         'Create start and sweep angles on ellipse.
    9.         Dim aStartL As Single = 180.0F
    10.         Dim aSweepL As Single = 90.0F
    11.         'Draw left arc to screen.
    12.         e.Graphics.DrawArc(BlackPen, rLeft, aStartL, aSweepL)
    13.         'Duplicate for right
    14.         Dim rRight As New Rectangle(Me.Width - 15, 0, 15, 15)
    15.         Dim aStartR As Single = 270.0F
    16.         Dim aSweepR As Single = 90.0F
    17.         e.Graphics.DrawArc(BlackPen, rRight, aStartR, aSweepR)
    18.         MyBase.OnPaint(e)
    19.     End Sub
    I think I need to do some kind of clipping on a pie area with the arc so the corners will appear rounded.
    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
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    See if this helps at all .Maybe needs some tweaking a little bit :
    Code:
    Function BorderRect() As Rectangle
    
    Dim rec As Rectangle = Me.Button1.ClientRectangle
    
    ReturnNew Rectangle(1, 1, rec.Width - 3, rec.Height - 3)
    
    EndFunction
    
    Sub DrawRoundedButtons(ByVal g As Graphics, ByVal p As Pen, ByVal rec As Rectangle, ByVal size As Size)
    
    Dim oldSmoothingMode As SmoothingMode = g.SmoothingMode
    
    g.SmoothingMode = SmoothingMode.AntiAlias
    
    g.DrawLine(p, rec.Left + size.Width \ 2, rec.Top, rec.Right - size.Width \ 2, rec.Top)
    
    g.DrawArc(p, rec.Right - size.Width, rec.Top, size.Width, size.Height, 270, 90)
    
    g.DrawLine(p, rec.Right, rec.Top + size.Height \ 2, rec.Right, rec.Bottom - size.Height \ 2)
    
    g.DrawArc(p, rec.Right - size.Width, rec.Bottom - size.Height, size.Width, size.Height, 0, 90)
    
    g.DrawLine(p, rec.Right - size.Width \ 2, rec.Bottom, rec.Left + size.Width \ 2, rec.Bottom)
    
    g.DrawArc(p, rec.Left, rec.Bottom - size.Height, size.Width, size.Height, 90, 90)
    
    g.DrawLine(p, rec.Left, rec.Bottom - size.Height \ 2, rec.Left, rec.Top + size.Height \ 2)
    
    g.DrawArc(p, rec.Left, rec.Top, size.Width, size.Height, 180, 90)
    
    g.SmoothingMode = oldSmoothingMode
    
    EndSub
    
    PrivateSub Button1_Paint(ByVal sender AsObject, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Button1.Paint
    
    DrawRoundedButtons(e.Graphics, New Pen(Color.Black), BorderRect, New Size(16, 16))
    
    EndSub
    
    

  4. #4

    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

  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

    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

  6. #6

    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

  7. #7
    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]

  8. #8

    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

  9. #9
    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? )????

  10. #10

    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

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by RobDog888
    Sorry about that. I mean Image List. I think it may be better to use an image as a resource?
    Lol
    Well , both would work fine I guess . But I would prefer a resource image (as I've seen a lot used to do that) . You will have more control over the image not like when you have it in imageList which it'll get resized and the color will change probably .I've not actually tried to use ImageList in a UserControl (maybe not preferable) .

  12. #12

    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 resource it is. Only problem is that I only know how to do it in VB6 only.
    Do you have an example that I can look over or ???

    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

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I've some but they're in C# , I'll send it now if you can read C# . Or I'll TRY to do that in VB.NET (just simple one) .

  14. #14

    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

    I havent done anything in C# yet, but I know its similar to C++, which I still only
    know a little of. Maybe between the both of us we could get a vb sample done?
    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

  15. #15
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Man , I forgot how to write code in VB.NET . Anyway , it's just a stupid sample that draws a picture on a panel from the a usercontrol class .
    Attached Files Attached Files
    Last edited by Pirate; Jan 25th, 2005 at 06:16 AM.

  16. #16
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    It's in VB.NET 2003 btw . You need to build the solution before you run or browse to the dll file . I'm sorry it's not commented but I'm here if you want to ask about anything .

  17. #17

    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

    Thanks, but I cant open it. I dont have WinRar. Could you upload a zip?
    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

  18. #18
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    It's zipped now (look up). Sry but I love winRAR .

  19. #19

    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

    Oh no. I'm not falling for that one!

    Thanks, be back in a bit after I have looked through it.
    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

  20. #20

    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, I have a question. If its a resource then why does the project still need
    the file (Image/MyImage.bmp)? I see its of type embedded so would that
    mean that when its compiled it will not need the image file?
    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

  21. #21
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by RobDog888
    Ok, I have a question. If its a resource then why does the project still need
    the file (Image/MyImage.bmp)? I see its of type embedded so would that
    mean that when its compiled it will not need the image file?
    When you compile it , it won't need these resources anymore . Try to compile it and take the exe + dll in any different folder , run . It should work without adding the resources to that folder . sry for the delay btw .

  22. #22

    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

    Doh! Ok, thanks I get it now. I just have to get it to draw from the resource now.
    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

  23. #23

    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

    Is this correct?
    VB Code:
    1. Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream("MyApp.MyPic.jpg")
    2. Dim bmp As Bitmap = New Bitmap(s)
    3. s.Close()
    4. Dim g As Graphics = CreateGraphics()
    5. g.DrawImage(bmp, 0, 0)
    6. bmp.Dispose()
    7. g.Dispose()
    But I need to draw my image that is round so the corners need to be transparent.
    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

  24. #24

    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

    How about setting a labels image property to the resource?
    Something like ...

    VB Code:
    1. Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream("MyApp.MyPic.jpg")
    2. Dim bmp As Bitmap = New Bitmap(s)
    3. s.Close()
    4. Label1.Image = bmp '? What is the correct syntax?
    5. bmp.Dispose()
    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

  25. #25

    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

    *BUMP*
    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

  26. #26
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by RobDog888
    Is this correct?


    visual basic code:Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream("MyApp.MyPic.jpg")

    Dim bmp As Bitmap = New Bitmap(s)
    s.Close()
    Dim g As Graphics = CreateGraphics()
    g.DrawImage(bmp, 0, 0)
    bmp.Dispose()


    g.Dispose()
    But I need to draw my image that is round so the corners need to be transparent.
    Shouldn't you resize the image(using bounds -1 all) to fit into your control (is it still panel or button) ?

  27. #27
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Quote Originally Posted by RobDog888
    How about setting a labels image property to the resource?
    Something like ...



    visual basic code:Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream("MyApp.MyPic.jpg")

    Dim bmp As Bitmap = New Bitmap(s)
    s.Close()
    Label1.Image = bmp '? What is the correct syntax?


    bmp.Dispose()
    This is correct and it should work since you passed correct args . I didn't try this though .

  28. #28

    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

    No, this is for the image associated with a label.

    How should I do it? What am i missing in my latest code I posted?

    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

  29. #29

    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, so as long as Label1.Image = bmp works I should be fine. I will test in a few.
    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

  30. #30

    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

    I'm getting an error for the stream. I dont know what namespace to import for it?
    VB Code:
    1. Dim s As [b]Stream[/b] = Me.GetType().Assembly.GetManifestResourceStream("MyApp.MyPic.jpg")
    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

  31. #31

    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

    Doh! found it - Imports System.IO

    Time to go to meeting. Be back.
    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

  32. #32

    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

    What am I doing wrong? Its crashing at the ?
    VB Code:
    1. Dim s As Stream = Me.GetType().Assembly.GetManifestResourceStream("2_138.ico")
    2.         Dim bmp As Icon = New Icon(s)
    3.         s.Close()
    4.         lnkSub1d.Image = CType(bmp, Icon).ToBitmap  '? What is the correct syntax?
    5.         bmp.Dispose()
    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

  33. #33
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Graphics - Rounded Corners & Drawing

    Why are you using the CType, it is already declared as an Icon. I think it should be bmp.ToBitmap.

  34. #34
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: Graphics - Rounded Corners & Drawing

    Little late in the game - but this is code a few of us in the forums had thrown together about 2 years ago but somehow got wiped off the code bank.. round gradient buttons (that move when you click em if I remember, so it appears like a button does when pressed)

    it is attached.
    Attached Files Attached Files

  35. #35

    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

    Its crashing on this line, and the resource is an icon.
    VB Code:
    1. Dim bmp As Icon = New Icon(s)
    It throws an exception.
    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

  36. #36

    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

    Resolved in this thread.
    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