Results 1 to 12 of 12

Thread: rounded corners on form using transparency key, but opacity change ruins it!

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    31

    rounded corners on form using transparency key, but opacity change ruins it!

    Hi guys,

    I am able to get the form to look rounded by using a background image with the corners using the same color as the transparency key, in settings.

    But, my app also requires runtime opacity change. When the opacity is changed on the app, the form corners are no longer transparent, because the color no longer matches the transparency key.

    How can i fix this?

    Thanks!

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    I had this problem a while ago, and posted here about it...I dont think I ever got a solution to my problem, so I dont think you'll get one either. But if you do, I'd be very interested to know.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    Don't use transparency. Use a Graphics path method (way) instead.

  4. #4
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: rounded corners on form using transparency key, but opacity change ruins it!


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

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    Dont use a background image. You need to draw it using GDI+ classes and place your code in the Form_Paint event.
    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
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    I am surprised how many people post questions that have the answers in the CodeBank of this forum. Check the link in my signature (Rounded-corner rectangles and controls). The code is written for you already I hope it helps.

  7. #7
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    That's just what I said; the only difference was I waved my hand horizontally.

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    31

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    Quote Originally Posted by VBDT
    I am surprised how many people post questions that have the answers in the CodeBank of this forum. Check the link in my signature (Rounded-corner rectangles and controls). The code is written for you already I hope it helps.
    Thank you very much for all your replies.

    fourblades, the link you posted was exactly what i did. This causes the corners to not be transparent when i change opacity during runtime.

    VBDT, I tried pasting the code

    Code:
        'End moving code
        'Draw a rounded rectangle in the forms paint event.
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            e.Graphics.DrawPath(Pens.Red, Shape.RoundedRectangle(New Rectangle(5, 5, 100, 100), 8))
        End Sub
    
    
        'Show the control on the form with rounded corners.
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Panel1.Region = Shape.RoundedRegion(Panel1.Size, 10)
        End Sub
    but i get shape and panel 11 as undeclared. How can I fix this?

  9. #9
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    Quote Originally Posted by GODzillaSDM
    Thank you very much for all your replies.

    fourblades, the link you posted was exactly what i did. This causes the corners to not be transparent when i change opacity during runtime.

    VBDT, I tried pasting the code

    Code:
        'End moving code
        'Draw a rounded rectangle in the forms paint event.
        Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
            e.Graphics.DrawPath(Pens.Red, Shape.RoundedRectangle(New Rectangle(5, 5, 100, 100), 8))
        End Sub
    
    
        'Show the control on the form with rounded corners.
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Panel1.Region = Shape.RoundedRegion(Panel1.Size, 10)
        End Sub
    but i get shape and panel 11 as undeclared. How can I fix this?
    It is because the example assumes that you have added the Shape class into your project and you have a Panel1 control on your form.
    Let make things simple, download the “Shape” zip file from the link, unzip it and add to your project by clicking the “Add New Item” button on VS tools, select the “Add Existing Item” menu item and add the class by browsing to the directory where the Shape.vb file is then select and click add. Put this code in the Form1.Load event and run the app.
    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Me.Region = Shape.RoundedRegion(Me.Size, 20)
        End Sub
    Check the parameters of the method for descriptions.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Apr 2007
    Posts
    31

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    thanks VBDT, it works great! although i honestly don't understand how your shape class works. (im somewhat noobish).

    i appreciate the help! thanks!

  11. #11
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    The base line is that it creates graphics path and from that it creates region. Check the class. I am glad it worked for you

  12. #12
    Frenzied Member
    Join Date
    Aug 2006
    Posts
    1,051

    Re: rounded corners on form using transparency key, but opacity change ruins it!

    You didn't read far enough down the page.

    To understand what VBDT's class is doing (in a much simpler example) scan down the page towards the bottom to find the following which gives a simple example of the way to use the Region/Graphics Path:

    Next Steps
    In the example above that used an instance of the GraphicsPath class, you specified a string, which was then used to determine the primary shape of the control. However, you may wish to have controls that are not text-shaped, but rather geometrically shaped (such as a triangle or circle). The .NET Framework includes provisions for this as well.

    Rather than specifying a string to render as the shape of the button, you can use shapes that have been predefined within the .NET Framework. Using these shapes in combination allows you a great degree of control over the look of your controls.

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