Draw all the Non-Client area in C#

后端 未结 3 545
陌清茗
陌清茗 2020-12-21 23:58

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 w

相关标签:
3条回答
  • 2020-12-22 00:31

    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.

    0 讨论(0)
  • 2020-12-22 00:42

    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.

    0 讨论(0)
  • 2020-12-22 00:42

    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 讨论(0)
提交回复
热议问题