c# - 将 WPF 窗口停靠到屏幕窗口的左侧/右侧 7/8

标签 c# .net wpf

在窗口窗体和 WPF 中都有这个 .WindowState 我可以将其设置为

最小化, 最大化正常

我想知道是否已经实现了类似的功能,可以将窗口停靠在屏幕的左侧/右侧,例如 Win + <-/ -> Windows 7/8 键?

我用谷歌搜索了一下,似乎人们调用 Win32 API 并自己实现它

我是否应该编写自定义对接代码,或者是否可以在诸如 WindowState 之类的地方设置一个简单的标志?

最佳答案

不,没有可以设置的标志。 Windows 改变了窗口的矩形,WPF 窗口除了矩形发生了变化之外,并不知道发生了什么。

自行更改矩形非常简单。 (实际上替换Windows的功能更具挑战性。)

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 StackOverflowWPF
{
   /// <summary>
   /// Interaction logic for MainWindow.xaml
   /// </summary>
   public partial class MainWindow : Window
   {
      public MainWindow()
      {
         InitializeComponent();
      }

      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
         this.Top = 0;
         this.Left = 0;
         System.Drawing.Rectangle screenBounds = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
         this.Width = screenBounds.Width / 2;
         this.Height = screenBounds.Height;
      }
   }
}

关于c# - 将 WPF 窗口停靠到屏幕窗口的左侧/右侧 7/8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23714559/

相关文章:

c# - 在 C# Web 应用程序中创建 Excel 文件时出错

.NET 标准与 .NET 核心

c# - 如何在 Window 启动 C# 时将 wpf 应用程序移动到最小化托盘?

c# - 在派生属性中使用调度程序以获得响应式 UI 的适当方法是什么?

javascript - 在asp项目中调用js文件

c# - 使用 selenium 下载没有直接 URL 的文件

.net - .NET 中的文档管理系统

c# - 在包含两个图像的 Canvas 上更改 UIElement.CaptureMouse() 的调用顺序时,我得到不同的结果

c# - 您如何使用 .net 2.0 中的 WebBrowser 控件检查 ajax 更新?

c# - string.Split 方法的运行时间