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();
    }
  • 相关阅读:
    JSTL笔记(胖先生版)
    EL表达式(胖先生版)
    包装类-Character
    String定义与方法
    冒泡排序(大熊版)
    tomcat Manger App
    第一天
    剑指offer:面试题5、从尾到头打印链表
    剑指offer:面试题4、替换空格
    剑指offer:面试题3、二维数组中的查找
  • 原文地址:https://www.cnblogs.com/lijianda/p/6603769.html
Copyright © 2011-2022 走看看