在窗口窗体和 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/