开发者

Draw all the Non-Client area in C#

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 exa开发者_JAVA技巧mple), 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.


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.


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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜