首页 > 代码库 > D23_03_非矩形窗口 (自定义窗体)
D23_03_非矩形窗口 (自定义窗体)
<Window x:Class="demo.TransparentBackground" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="TransparentBackground" Height="300" Width="300" AllowsTransparency="True" WindowStyle="None" MouseLeftButtonDown="window_MouseLeftButtonDown" > <!--AllowsTransparency:启用窗体透明对,WindowStyle:设置WindowStyle为None,MouseLeftButtonDown:定义鼠标左键 按下时的处理事件,Window.Background设置Window的背景--> <Window.Background> <ImageBrush ImageSource="shapes.png"></ImageBrush> </Window.Background> <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Button Margin="20">A Sample Button</Button> <Button Margin="20" Grid.Row="2" Click="cmdClose_Click" >Close</Button> </Grid></Window>
TransparentBackground (窗体类)
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace demo{ /// <summary> /// TransparentBackground.xaml 的交互逻辑 /// </summary> public partial class TransparentBackground : Window { public TransparentBackground() { InitializeComponent(); } private void cmdClose_Click(object sender, RoutedEventArgs e) { this.Close(); } private void window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { this.DragMove(); } }}
D23_03_非矩形窗口 (自定义窗体)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。