wpf窗体程序全屏显示,wpf退出限制,wpf窗口禁止移动

this.Topmost = true慎用,会遮挡对话框,造成无法操作,事件根据情况进行编写,或自动生成

 ((MainWindowsView)(target)).Closing += new System.ComponentModel.CancelEventHandler(this.ModernWindow_Closing);
 ((MainWindowsView)(target)).Loaded += new System.Windows.RoutedEventHandler(this.ModernWindow_Loaded);

第一种设置全屏的方式

                // 设置全屏
                this.WindowState = System.Windows.WindowState.Normal;
                this.WindowStyle = System.Windows.WindowStyle.None;
                this.ResizeMode = System.Windows.ResizeMode.CanMinimize;
                this.ResizeMode = ResizeMode.NoResize;
                //抓住焦点
                //this.Topmost = true;
                this.Left = 0.0;
                this.Top = 0.0;
                this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
                this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

 第二种设置全屏的方式

private void ModernWindow_Loaded(object sender, RoutedEventArgs e)
        {
            if (SysSettings.Default.IsFullScreen)
            {
                 设置全屏
                //不显示最大化和最小化按钮
                this.ResizeMode = System.Windows.ResizeMode.NoResize;
                //窗口在最前
                //this.Topmost = true; 

                this.Left = 0.0;
                this.Top = 0.0;
                this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
                this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;

                //窗口初始化后指定钩子函数
                IntPtr hwnd = new System.Windows.Interop.WindowInteropHelper(this).Handle;
                System.Windows.Interop.HwndSource.FromHwnd(hwnd).AddHook(new System.Windows.Interop.HwndSourceHook(WndProc));

                IntPtr handle = new System.Windows.Interop.WindowInteropHelper(this).Handle;
                IntPtr hmenu = GetSystemMenu(handle, 0);
                int cnt = GetMenuItemCount(hmenu);
                for (int i = cnt - 1; i >= 0; i--)
                {
                    StringBuilder tmpstr = new StringBuilder(100);
                    GetMenuString(hmenu, (uint)i, tmpstr, 255, MF_DISABLED | MF_BYPOSITION);
                    if (tmpstr.ToString().Contains("移动"))
                    {
                        RemoveMenu(hmenu, i, MF_DISABLED | MF_BYPOSITION);
                    }
                }
            }
            else
            {
                this.Width = 1024;
                this.Height = 768;
            }
        }

        //钩子函数的实现
        private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            //拦截标题栏双击和窗口移动事件
            if (msg == 0x00A3 || msg == 0x0003 || wParam == (IntPtr)0xF012)
            {
                handled = true;
                wParam = IntPtr.Zero;
            }
            return IntPtr.Zero;
        }

        [DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
        private static extern IntPtr GetSystemMenu(IntPtr hwnd, int revert);

        [DllImport("user32.dll", EntryPoint = "RemoveMenu")]
        private static extern int RemoveMenu(IntPtr hmenu, int npos, int wflags);

        [DllImport("user32.dll", EntryPoint = "GetMenuItemCount")]
        private static extern int GetMenuItemCount(IntPtr hmenu);

        [DllImport("user32.dll", EntryPoint = "GetMenuStringW", CharSet = CharSet.Unicode)]
        private static extern int GetMenuString(IntPtr hMenu, uint uIDItem, StringBuilder lpString, int cchMax, uint flags);

        //键值
        private const int MF_BYPOSITION = 0x0400;
        private const int MF_DISABLED = 0x0002;

关闭窗体密码效验功能

private void ModernWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            System.Windows.Style style = new System.Windows.Style();
            style.Setters.Add(new Setter(Xceed.Wpf.Toolkit.MessageBox.YesButtonContentProperty, "是!"));
            style.Setters.Add(new Setter(Xceed.Wpf.Toolkit.MessageBox.NoButtonContentProperty, "否!"));
            MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show("确认", "是否退出程序", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.Yes, style);
            if (result == MessageBoxResult.Yes)
            {
                //程序退出
                e.Cancel = false;
            }
            else
            {
                //终止退出进程
                e.Cancel = true;
            }
        }

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
WPF(Windows Presentation Foundation)窗体应用程序是使用微软的.NET框架开发的一种桌面应用程序。UDP(User Datagram Protocol)通讯是一种面向无连接的网络通信协议,具有低延迟和高效率的特点。在WPF窗体应用程序中使用UDP通讯框架可以实现实时数据传输和通信。 在WPF窗体应用程序中,我们可以使用.NET框架中的System.Net命名空间提供的相关类来实现UDP通讯功能。首先,我们需要创建一个UDPClient对象来作为通讯的接口,通过指定远程主机和端口号来初始化该对象。然后,我们可以使用UDPClient提供的方法来收发UDP数据报,如Send方法用于发送数据报,Receive方法用于接收数据报。 在WPF窗体应用程序中,我们可以通过UI线程和后台线程来实现UDP通讯框架。UI线程用于处理用户界面的显示操作,后台线程用于处理UDP数据的发送和接收。可以使用异步编程的方式,在后台线程上执行UDP通讯的相关操作,以避免阻塞UI线程,提高应用程序的响应性能。 在使用UDP通讯框架时,我们需要注意数据的分包和重组,以及数据的校验和错误处理。由于UDP是一种不可靠的通讯协议,数据的丢失或损坏是可能的,因此我们需要在应用层面进行数据的可靠性保证和错误处理。 综上所述,WPF窗体应用程序中的UDP通讯框架可以通过使用.NET框架中的相关类来实现,通过UI线程和后台线程配合实现数据的收发,并进行数据的分包和重组、校验和错误处理以保证通讯的可靠性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花开花落的个人博客

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值