Smooth edges of non-rectangular form in .NET

柔情痞子 提交于 2019-12-01 16:00:44

问题


I've created a form with rounded corners using Form.Region. It works, but unfortunately the rounding appears rough. Are there any tricks for smoothing such shaped form corners? I know many applications support this, just not sure how to make it in .NET.

Thanks guys.


回答1:


There is no good fix for this, regions cannot be anti-aliased. This is inevitable, anti-aliasing only works when you know the background colors so you can blend properly. That's not an option for windows, the background is by design unpredictable. If this is a splash screen then you can fake it by taking a screen shot of the background and drawing your fake window on top of it. Won't work for more than a few seconds.

Best thing to do is to keep the corner radius small so it is not so noticeable. Also use a tool like SysInternals' ZoomIt and take a close look at the rounded corners of a program like Windows Media Player. Note the gray tones it uses to draw the border.




回答2:


From what I've read online most people end up overriding the forms onpaint event and drawing the region there. This allows them to use GDI+ with antialiasing and make it look much cleaner.

The examples I found:

http://netcode.ru/dotnet/?lang=&katID=30&skatID=283&artID=7833 http://www.xtremevbtalk.com/showthread.php?t=288178



来源:https://stackoverflow.com/questions/4727726/smooth-edges-of-non-rectangular-form-in-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!