Shaped form in VB.net

seema.nare@oasis-bs.com

Active member
Joined
May 19, 2006
Messages
27
Programming Experience
Beginner
I've created the shaped form in VB.net setting the background as the image with stretched property.
I've set the transperency key with the magenta color. The form appears good under 24 bit color depth but 32bit color depth shows the color around the round corners of my form.
Is there any solution for this which will work on any color bit depth?
Following link mentions the same :

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchShapedWindowsFormsControlsInVisualStudioNET.asp

I'm not able to solve this problem.

Please help.
Regards.

”</SPAN>
 
Last edited by a moderator:
I have the same problem. I changed the transparency key to become a darker color. A better idea is, if the form is a constant color choose a transparency key close to the color of the edges of the form. But this also helps.
VB.NET:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Overrides[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] OnPaint([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] PaintEventArgs)
[/SIZE][SIZE=2]   e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]

Place that in the paint event that your using, or a variation of it. I am assuming you are overriding the onpaint event. This should touch up the edges a lot.
Also, I noticed a significant difference in using the form when customizing graphics if you make the forms double buffered property true. But this will not help the edges.
 
There is an article in a book by Francesco Balena - with code. I can't offhand think of the title of the book but it is huge and heavy. I will look and post info. I do have the code. Would you like it? It is quite short.
 
Yes, that is the same book I read. Great author. Still have the book, that is actually where I learned that also. Definately reccomend reading it if you haven't read a good book on VB and this book covers nearly everything. I don't think he has a 2005 version out but it's still worth reading the 2003 version.
 
Forget the transparency ket it's justa bit to twitchy for my liking. Use the forms protected region property instead. Any shape that you set the region property to is the only bit that will get painted. Works for most other controls too.
 
Ohh. I could solve the problem using the dll, that cut my round corner edges of form. And solution works on each color quality, resolution m/c.
But probably, I could solve by this method because simple round corners were used in the form. If those were of differnt shapes, then that would have been much difficult.
Still I am searching for better solution.
 
Back
Top