|
-
Aug 14th, 2007, 04:45 PM
#1
Thread Starter
Junior Member
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!
-
Aug 14th, 2007, 04:48 PM
#2
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.
-
Aug 14th, 2007, 06:09 PM
#3
Frenzied Member
Re: rounded corners on form using transparency key, but opacity change ruins it!
Don't use transparency. Use a Graphics path method (way) instead.
-
Aug 14th, 2007, 06:13 PM
#4
Frenzied Member
Re: rounded corners on form using transparency key, but opacity change ruins it!
-
Aug 14th, 2007, 06:32 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 14th, 2007, 07:14 PM
#6
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.
-
Aug 14th, 2007, 07:25 PM
#7
Frenzied Member
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.
-
Aug 14th, 2007, 08:24 PM
#8
Thread Starter
Junior Member
Re: rounded corners on form using transparency key, but opacity change ruins it!
 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?
-
Aug 14th, 2007, 10:45 PM
#9
Re: rounded corners on form using transparency key, but opacity change ruins it!
 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.
Last edited by VBDT; Aug 14th, 2007 at 10:51 PM.
-
Aug 15th, 2007, 12:36 AM
#10
Thread Starter
Junior Member
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!
-
Aug 15th, 2007, 12:42 AM
#11
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
-
Aug 15th, 2007, 03:23 AM
#12
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|