[英]Draw all the Non-Client area in C#
例如,我想在C#中绘制非客户区域,而不是矩形作为表单,我想要一个椭圆形(这是一个示例),但是我该怎么做呢?
我基本上想绘制我所有的非客户区域,我想要做的就是重写一些方法,但是哪些方法呢?
我发现了一个使用“ xaml”的示例,我认为这是Windows Presentation Foundation应用程序,但是我不太了解。
m0sa已经提供了WPF答案 。
对于WinForms,您将需要处理WM_NCPAINT
消息(重写Control.WndProc
),并启用分层窗口样式,以便在边界框中具有透明区域。
您必须像这样设置窗口xaml文件
<Window x:Class="[YourwindowClass]"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="..."
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent">
[Draw the window]
</Windows>
如果您正在谈论Winforms,并且想在“非客户”区域中绘画 ,Ben的建议将起作用。
如果您希望窗口具有不同的形状-说“像时钟一样圆”,那么您将在查看“区域”。
GraphicsPath path = new GraphicsPath();
path.AddEllipse(100, 100, 100, 100);
this.Region = new Region(path);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.