码迷,mamicode.com
首页 > Windows程序 > 详细

D23_03_非矩形窗口 (自定义窗体)

时间:2014-11-02 13:46:50      阅读:157      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   strong   

bubuko.com,布布扣

 

<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_非矩形窗口 (自定义窗体)

标签:style   blog   http   io   color   ar   os   sp   strong   

原文地址:http://www.cnblogs.com/xiepengtest/p/4069097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!