Draw all the Non-Client area in C#

ⅰ亾dé卋堺 提交于 2019-11-30 09:47:08

问题


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

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