WPF 入门(1)—自定义关闭按钮

目标:由于需求界面美观,圆角边距等等,所以整个界面使用背景图,去除自带边框及按钮。

  1.去除系统自带边框、按钮。

      2.自定义退出按钮,并对退出进行提示框提示,同时解决了Alt+F4退出的不提示的问题。

操作:

     设置Window属性 AllowsTransparency="True" 透明

                             WindowStyle="None"          去除边框

           MouseDown="Window_MouseDown"  由于没有边框无法鼠标拖动,所以定义拖动方法

           Closing="Window_Closing"> 设置页面关闭触发方法

<Window x:Class="QfpayPC.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="740" Width="936" 
        AllowsTransparency="True" 
        WindowStyle="None" 
        MouseDown="Window_MouseDown" 
        Closing="Window_Closing">

  Window_MouseDown:

//界面可以拖动
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
     if (e.LeftButton == MouseButtonState.Pressed)
        {
                DragMove();
        }
}

Window_Closing:

//退出提示程序
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
            MessageBoxResult result = MessageBox.Show("正在交易中,您真的要退出吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (result == MessageBoxResult.Yes)
            {
                Application.Current.Shutdown();
            }
            else
            {
                e.Cancel = true;
            }
}

自定义关闭按钮、最小化按钮

private void btnClose_Click(object sender, RoutedEventArgs e){
            this.Close();
}
private void btnClose_Click(object sender, RoutedEventArgs e){
this.WindowState = WindowState.Minimized;
}

 

转载于:https://www.cnblogs.com/xiaoxige/archive/2012/08/07/2627235.html

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值