首页 > 其他分享 >WPF Control+C short cuts to close the window

WPF Control+C short cuts to close the window

时间:2024-09-23 10:13:21浏览次数:1  
标签:Control short Windows System window close using MainWindow

//xaml
<Window x:Class="WpfApp402.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp402"
        mc:Ignorable="d"
        WindowState="Maximized"
        KeyDown="Window_KeyDown"
        Title="MainWindow" Height="450" Width="800">
    <Window.Background>
        <ImageBrush ImageSource="/Images/1.jpg"/>
    </Window.Background>
    <Grid>
        
    </Grid>
</Window>


//cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Navigation;
using System.Windows.Shapes;

namespace WpfApp402
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if((Keyboard.Modifiers == ModifierKeys.Control) && e.Key==Key.C)
            {
                var msgResult = MessageBox.Show("Are you sure to exit?", "Exit", MessageBoxButton.YesNo);
                if(msgResult == MessageBoxResult.Yes)
                {
                    this.Close();
                }
            }
        }
    }
}

 

标签:Control,short,Windows,System,window,close,using,MainWindow
From: https://www.cnblogs.com/Fred1987/p/18426495

相关文章

  • windows文件标识符
    回收站.{645ff040-5081-101b-9f08-00aa002f954e}回收站(满).{5ef4af3a-f726-11d0-b8a2-00c04fc309a4}拨号网络.{992CFFA0-F557-101A-88EC-00DD010CCC48}打印机.{2227a280-3aea-1069-a2de-08002b30309d}控制面板.{21ec2020-3aea-1069-a2dd-08002b30309d}网上邻居.{208D2C60-3AEA-10......
  • window10/11永久关闭系统更新
    联想知识库官网有教程,但要下软件,所以我找到一个更直接的。1.打开window+r:输入:regedit。2.打开注册表后地址输入: 计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings然后回车,如下:3.右击新建32位文件名字为:FlightSettingsMaxPauseDays ,......
  • WPF ContextMenu MenuItem CommandParameter pass whole control or SelectedItem
    CommandParameterpassSelectedItemofcontrol<ListBox.ContextMenu><ContextMenu><MenuItemHeader="SaveImage"Command="{BindingSaveImgCommand}"CommandParameter=&q......
  • 从规范到实现解读Windows平台如何播放RTSP流
    RTSP播放器应用场景RTSP播放器在视频监控、远程视频会议、网络电视、实时流媒体传输、协同操控相关的智能设备、教育培训以及企业内部通讯与协作等多个领域都有着广泛的应用场景。1.视频监控RTSP直播播放器在视频监控系统中扮演着重要角色。通过RTSP协议,播放器可以实时接收来自监......
  • windows10事件代码1074自动重启进程 C:\WINDOWS\system32\svchost.exe用户 NT AUTH
    PSC:\WINDOWS\system32>Get-Eventlog-LogNameSystem-Source"User32"-Newest1|Where-Object{$_.EventID-eq1074}|fl*EventID:1074MachineName:DESKTOP-4COHMG5Data:{}Index:5515......
  • [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\partmgr\Parameters] "SanP
    WindowsRegistryEditorVersion5.00;关闭windowstogo特性[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control]"PortableOperatingSystem"=dword:00000000 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\partmgr\Parameters]"SanPolicy"=......
  • WPF Unable to cast object of type 'System.Windows.Controls.SelectedItemCollectio
    SelectedItemsconverttoIListasbelowfailed;IList<Book>collection2=(IList<Book>)obj; System.InvalidCastExceptionHResult=0x80004002Message=Unabletocastobjectoftype'System.Windows.Controls.SelectedItemCollection'......
  • mysql安装(windows-mysql-8.1.0-winx64.zip安装)
    1、官网下载,解压缩2、配置环境变量3、新增my.ini文件,根据电脑环境修改配置 #设置mysql的安装目录 basedir #设置mysql数据库的数据的存放目录 datadirmy.ini文件内容如下:[mysqld]#设置3306端口port=3306#设置mysql的安装目录basedir=D:\kaifa\mysql-8.1.0-winx6......
  • WPF System.Windows.MessageBox.Show Dispatcher processing has been suspended, bu
    privatevoidSelectedCommandExecuted(objectobj){if(obj!=null&&objisDataGriddg){if(dg!=null){varselectedBks=dg.SelectedItems;if(selectedBks!=null&&selectedBk......
  • 不小心把Windows资源管理器关闭了怎么办
    因为在压缩文件夹的时候Windows资源管理器给卡死了,怎么都关不了所以进行了一个很降智的操作...打开任务管理器,把Windows资源管理器给“结束任务”了...一瞬间,电脑开始闪屏,然后最底下那条任务栏菜单全部消失不见,按windows键都没反应...幸亏浏览器界面还在,赶紧搜索怎么恢复当意......