zoukankan      html  css  js  c++  java
  • WPF中控制窗口显示位置的三种方式

    首先新建一个WPF工程,在主界面添加一个按钮,并给按钮添加点击事件button1_Click,然后新建一个用于测试弹出位置的窗口TestWindow。
    1、在屏幕中间显示,设置window.WindowStartupLocation = WindowStartupLocation.CenterScreen;

    private void button1_Click(object sender, RoutedEventArgs e)
    {
    TestWindow window = new TestWindow();
    window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
    window.ShowDialog();
    }

    2、在父窗口中间显示,

    设置window.WindowStartupLocation = WindowStartupLocation.CenterOwner;,并指定Owner。

    private void button1_Click(object sender, RoutedEventArgs e)
    {
    TestWindow window = new TestWindow();
    window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
    window.Owner = this;
    window.ShowDialog();
    }


    3、在任意位置显示,设置window.WindowStartupLocation = WindowStartupLocation.Manual;并制定窗口的Left和Top坐标。

    private void button1_Click(object sender, RoutedEventArgs e)
    {
    TestWindow window = new TestWindow();
    window.WindowStartupLocation = WindowStartupLocation.Manual;
    window.Left = 0;
    window.Top = 0;
    window.ShowDialog();
    }
  • 相关阅读:
    343. Integer Break
    338. Counting Bits
    322. Coin Change
    304. Range Sum Query 2D
    303. Range Sum Query
    221. Maximal Square
    213. House Robber II
    cf
    poj2478欧拉函数
    lightoj1138
  • 原文地址:https://www.cnblogs.com/lijianda/p/6603769.html
Copyright © 2011-2022 走看看