Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将WPF窗口停靠在屏幕窗口的左/右侧7/8_C#_.net_Wpf - Fatal编程技术网

C# 将WPF窗口停靠在屏幕窗口的左/右侧7/8

C# 将WPF窗口停靠在屏幕窗口的左/右侧7/8,c#,.net,wpf,C#,.net,Wpf,在窗口窗体和WPF中都有我可以设置为的.WindowState 最小化, 最大化或正常 我想知道是否已经实现了类似的功能,将窗口停靠在屏幕的左/右两侧,如Windows 7/8的Win+键 我在谷歌上搜索过,人们似乎调用Win32 API并自行实现 我应该写一个自定义的停靠代码,还是有一个简单的标志可以设置在某个地方,比如WindowState?不,没有一个标志可以设置。Windows更改窗口的矩形,WPF窗口不知道发生了什么,只知道矩形已更改 自行更改矩形非常简单。(实际上,更换Windows

在窗口窗体和WPF中都有我可以设置为的
.WindowState

最小化
最大化
正常

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

我在谷歌上搜索过,人们似乎调用Win32 API并自行实现


我应该写一个自定义的停靠代码,还是有一个简单的标志可以设置在某个地方,比如
WindowState

不,没有一个标志可以设置。Windows更改窗口的矩形,WPF窗口不知道发生了什么,只知道矩形已更改

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

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间StackOverflowWPF
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
这个.Top=0;
左=0;
System.Drawing.Rectangle screenBounds=System.Windows.Forms.Screen.PrimaryScreen.Bounds;
this.Width=screenBounds.Width/2;
this.Height=screenBounds.Height;
}
}
}

不,没有可设置的标志。Windows更改窗口的矩形,WPF窗口不知道发生了什么,只知道矩形已更改

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

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows;
使用System.Windows.Controls;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间StackOverflowWPF
{
/// 
///MainWindow.xaml的交互逻辑
/// 
公共部分类主窗口:窗口
{
公共主窗口()
{
初始化组件();
}
私有无效按钮\u单击\u 1(对象发送者,路由目标)
{
这个.Top=0;
左=0;
System.Drawing.Rectangle screenBounds=System.Windows.Forms.Screen.PrimaryScreen.Bounds;
this.Width=screenBounds.Width/2;
this.Height=screenBounds.Height;
}
}
}

Related:@TFD您的礼貌被破坏了?Related:@TFD您的礼貌被破坏了?窗口最大化状态不仅仅是不同的边界。不是从WPF窗口的角度。Windows自己跟踪矩形。WPF窗口不知道发生了什么,只知道矩形已经改变。我根据@Banana所说的对我的答案进行了一些改进。窗口最大化状态不仅仅是不同的边界。不是从WPF窗口的角度来看的。Windows自己跟踪矩形。WPF窗口不知道发生了什么,只知道矩形已经改变了。我根据@Banana所说的改进了我的答案。
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;
      }
   }
}