问题
I am looking to draw my non-client area in C#, for example, instead a rectangle as a form, i want an ellipse (this is an example), but how can i do it?
I basically want to draw all my non client area, and i think to do that i will have to override some methods, but which ones?
I have found an example that uses 'xaml', what i think that is windows presentation foundation app, but i haven't understand it well.
回答1:
m0sa has provided a WPF answer already.
For WinForms, you'll need to process the WM_NCPAINT
message (override Control.WndProc
) and also enable the layered window style in order to have transparent regions in the bounding box.
回答2:
You have to set the window xaml file like this
<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>
You will need to generate your own click handlers for dragging the window though. There are some examples here and here.
回答3:
If you are talking Winforms, and want to draw in the Non Client area, Ben's suggestion will work.
If you want your window a different shape - say Round like a clock, then you will be looking at Regions.
GraphicsPath path = new GraphicsPath();
path.AddEllipse(100, 100, 100, 100);
this.Region = new Region(path);
来源:https://stackoverflow.com/questions/5254161/draw-all-the-non-client-area-in-c-sharp