wpf 不規(guī)則窗體
WPF布局(1)-簡(jiǎn)單不規(guī)則窗體
如果想制作一個(gè)不規(guī)則形狀的窗體可以采取以下步驟:
1、設(shè)置窗體屬性
this.WindowStyle = WindowStyle.None;//設(shè)置成無(wú)邊框形式
this.Background = null;//設(shè)置背景色為空(即黑色)。
this.AllowsTransparency = true;//設(shè)置窗體允許透明,這樣我們就可以通過透明度:Opacity或者Opacitymask 對(duì)它進(jìn)行透明度設(shè)置。
2、設(shè)置一個(gè)border作為窗體的content
如:
Border m_border = new Border();
this.Content = m_border;//設(shè)置border內(nèi)容
m_border.CornerRadius = new CornerRadius(10);//設(shè)置Borer圓角
m_border.Background = Brushes.White;//設(shè)置border背景色
m_border.BorderBrush = Brushes.Linen;//設(shè)置border邊框顏色
m_border.BorderThickness = new Thickness(3);//設(shè)置border邊框厚度
3、窗體的拖動(dòng)
WPF提供了DragMove方法,只須在相應(yīng)某控件的MouseLeftButton事件函數(shù)中調(diào)用此函數(shù)即可,實(shí)現(xiàn)窗體的拖動(dòng)。
4、窗體的關(guān)閉
由于此窗體為None,無(wú)邊框形式,所以可以制作一個(gè)小的按鈕作為關(guān)閉按鈕,點(diǎn)擊時(shí)相應(yīng)this.Close方法即可。
wpf 生成不規(guī)則窗體
來(lái)源:http://www.rzrgm.cn/DragonInSea/archive/2009/04/10/1432956.html
使用異形窗體,可以將窗體的背景設(shè)置為透明,邊框設(shè)置為空,然后利用控件做出異形的窗體,例如:
另外,還要把窗體背景設(shè)置為 null, Background="{x:Null}"
XAML:
1: <Window x:Class="WpfWindow.CustomerWindow"
2: xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3: xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4: Title="NonRectangularWindowSample" SizeToContent="WidthAndHeight"
5: MouseLeftButtonDown="NonRectangularWindow_MouseLeftButtonDown"
6: WindowStyle="None"
7: AllowsTransparency="True"
8: Background="Transparent">
9: <Canvas Width="200" Height="200" >
10: <Path Stroke="DarkGray" StrokeThickness="2">
11: <Path.Fill>
12: <LinearGradientBrush StartPoint="0.2,0" EndPoint="0.8,1" >
13: <GradientStop Color="White" Offset="0"></GradientStop>
14: <GradientStop Color="White" Offset="0.45"></GradientStop>
15: <GradientStop Color="LightBlue" Offset="0.9"></GradientStop>
16: <GradientStop Color="Gray" Offset="1"></GradientStop>
17: </LinearGradientBrush>
18: </Path.Fill>
19: <Path.Data>
20: <PathGeometry>
21: <PathFigure StartPoint="40,20" IsClosed="True">
22: <LineSegment Point="160,20"></LineSegment>
23: <ArcSegment Point="180,40" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
24: <LineSegment Point="180,80"></LineSegment>
25: <ArcSegment Point="160,100" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
26: <LineSegment Point="90,100"></LineSegment>
27: <LineSegment Point="90,150"></LineSegment>
28: <LineSegment Point="60,100"></LineSegment>
29: <LineSegment Point="40,100"></LineSegment>
30: <ArcSegment Point="20,80" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
31: <LineSegment Point="20,40"></LineSegment>
32: <ArcSegment Point="40,20" Size="20,20" SweepDirection="Clockwise"></ArcSegment>
33: </PathFigure>
34: </PathGeometry>
35: </Path.Data>
36: </Path>
37: <Label Width="200" Height="120" FontSize="15" HorizontalContentAlignment="Center"
VerticalContentAlignment="Center">Drag Me</Label>
38: <Button Canvas.Left="155" Canvas.Top="30" Click="closeButtonRectangle_Click">
39: <Button.Template>
40: <ControlTemplate>
41: <Canvas>
42: <Rectangle Width="15" Height="15" Stroke="Black" RadiusX="3" RadiusY="3">
43: <Rectangle.Fill>
44: <SolidColorBrush x:Name="myAnimatedBrush" Color="Red" />
45: </Rectangle.Fill>
46: </Rectangle>
47: <Line X1="3" Y1="3" X2="12" Y2="12" Stroke="White" StrokeThickness="2"></Line>
48: <Line X1="12" Y1="3" X2="3" Y2="12" Stroke="White" StrokeThickness="2"></Line>
49: </Canvas>
50: </ControlTemplate>
51: </Button.Template>
52: </Button>
53: </Canvas>
54: </Window>
posted on 2010-02-23 20:29 大寶pku 閱讀(2206) 評(píng)論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)