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!
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.
Re: rounded corners on form using transparency key, but opacity change ruins it!
Don't use transparency. Use a Graphics path method (way) instead.
Re: rounded corners on form using transparency key, but opacity change ruins it!
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.
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.
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.
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?
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.
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!
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 :)
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.