WPF 非矩形視窗的建立

2022-02-21 11:58:05 字數 1891 閱讀 7593

一、視窗的allowstransparency設定為true

第二、視窗的background設定為transparent

第三、視窗的windowstyle設定為none

第四、視窗內的grid用clip或者border設定為需要的形狀

**示例(利用clip實現圓角視窗)

1

<

window

x:class

="test"

2xmlns

=""3xmlns:x

=""4xmlns:d

=""5xmlns:mc

=""6xmlns:local

="clr-namespace:caipiaoui"

7mc:ignorable

="d"

8title

="test"

height

="500"

width

="500"

windowstyle

="none"

allowstransparency

="true"

9background

="transparent"

windowstartuplocation

="centerscreen"

>

10<

grid

background

="blue"

>

11<

grid.clip

>

12<

rectanglegeometry

radiusx

="50"

radiusy

="50"

rect

="0,0,500,500"

>

rectanglegeometry

>

13grid.clip

>

14grid

>

15window

>

**示例(利用border實現圓角視窗)

1

<

window

x:class

="test"

2xmlns

=""3xmlns:x

=""4xmlns:d

=""5xmlns:mc

=""6xmlns:local

="clr-namespace:caipiaoui"

7mc:ignorable

="d"

8title

="test"

height

="500"

width

="500"

windowstyle

="none"

allowstransparency

="true"

9background

="transparent"

windowstartuplocation

="centerscreen"

>

10<

grid

>

11<

border

borderthickness

="20"

cornerradius

="50"

background

="blue"

>

border

>

12grid

>

13window

>

這裡特別注意一點,就是視窗背景色設定的位置:

clip實現方式中,視窗背景色設定在grid上;

border實現方式中,視窗背景色設定在border上。

C 建立非矩形窗體

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system.window...

WPF 建立無邊框的圓角視窗

首先將窗體的背景設為透明,將允許透明的屬性設定為true,即 background transparent allowstransparency true 將window的windowstyle屬性設定為none,即windowstyle none 當allowstransparency true ...

建立乙個非矩形按鈕

動態建立乙個按鈕 hwndarrowbutton createwindow l button 視窗型別,為按鈕 null,ws visible ws popup bs ownerdraw,按鈕樣式 428,66,50,50,按鈕位置和大小 hwnd,父視窗控制代碼 hmenu id arrow up...