WinForm 窗体显示位置

          窗体显示的位置首先由窗体的StartPosition决定,FormStartPosition这个枚举值由如下几种情况
// 摘要:
// 窗体的位置由 System.Windows.Forms.Control.Location 属性确定。
Manual = ,
//
// 摘要:
// 窗体在当前显示窗口中居中,其尺寸在窗体大小中指定。
CenterScreen = ,
//
// 摘要:
// 窗体定位在 Windows 默认位置,其尺寸在窗体大小中指定。
WindowsDefaultLocation = ,
//
// 摘要:
// 窗体定位在 Windows 默认位置,其边界也由 Windows 默认决定。
WindowsDefaultBounds = ,
//
// 摘要:
// 窗体在其父窗体中居中。
CenterParent = ,

1、显示的窗体位于屏幕的中心

MainForm mainForm = new MainForm();
mainForm.StartPosition = FormStartPosition.CenterScreen;//显示位于当前屏幕的中心位置
mainForm.Show();

2、显示位于主窗体的中心位置

dlg.StartPosition = FormStartPosition.CenterParent;//能够这样做的前提是主窗体必须先定义和显示。否则登录窗体可能无法找到父窗体。
dlg.ShowDialog();

3、手动设置显示的具体位置(常用)

 要想显示在自己设置的任意位置,首先必须设置ForStartPosion的枚举值为Manual,
dlg.StartPosition=FormStartPosition.Manual;
随后获取屏幕的分辨率,也就是显示器屏幕的大小。
int xWidth = SystemInformation.PrimaryMonitorSize.Width;//获取显示器屏幕宽度
int yHeight = SystemInformation.PrimaryMonitorSize.Height;//高度
然后定义窗口位置,以主窗体为例
mainForm.Location = new Point(xWidth/, yHeight/);//这里需要再减去窗体本身的宽度和高度的一半
mainForm.Show();

Wpf 窗体是显示位置和winform类似

、在屏幕中间显示,设置window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
private void button1_Click(object sender, RoutedEventArgs e)
{
TestWindow window = new TestWindow();
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
window.ShowDialog();
}
、在父窗口中间显示,设置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();
}
、在任意位置显示,设置window.WindowStartupLocation = WindowStartupLocation.Manual;并制定窗口的Left和Top坐标。
private void button1_Click(object sender, RoutedEventArgs e)
{
TestWindow window = new TestWindow();
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Left = ;
window.Top = ;
window.ShowDialog();
}

Winform WPF 窗体显示位置的更多相关文章

  1. WinForm 设置窗体启动位置在活动屏幕右下角

    WinForm 设置窗体启动位置在活动屏幕右下角 在多屏幕环境下, 默认使用鼠标所在的屏幕 1. 设置窗体的 StartPosition 为 FormStartPosition.Manual. 2. ...

  2. WinForm开发,窗体显示和窗体传值相关知识总结

    主窗体中代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...

  3. WPF 窗体显示最前端

    原文:WPF 窗体显示最前端 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jjx0224/article/details/8782845 如何做一 ...

  4. Winform将一个窗体显示在另一个窗体中

    private void ShowForm(Form Indexform) { Form1 form1 = new Form1(); form1 .TopLevel = false; form1 .P ...

  5. WPF C# 多屏情况下,实现窗体显示到指定的屏幕内

    原文:WPF C# 多屏情况下,实现窗体显示到指定的屏幕内 针对于一个程序,需要在两个显示屏上显示不同的窗体,(亦或N个显示屏N个窗体),可以使用如下的方式实现. 主要涉及到的:System.Wind ...

  6. 【转】WinForm窗体显示和窗体间传值

    以前对WinForm窗体显示和窗体间传值了解不是很清楚 最近做了一些WinForm项目,把用到的相关知识整理如下 A.WinForm中窗体显示 显示窗体可以有以下2种方法: Form.ShowDial ...

  7. C#:控制WinForm界面的显示

    控制WinForm界面在屏幕的四个角落显示,具体代码中有说明: using System; using System.Collections.Generic; using System.Drawing ...

  8. Winform窗口弹出位置控制

    窗体的弹出位置可以由属性StartPosition来指定,默认值有: Manural 自定义,由属性Location指定: CenterScreen 屏幕中央: WindowsDefaultBound ...

  9. WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体

    原文:http://blog.csdn.net/kiss0622/article/details/5852153 方法一: 1.父窗口代码 Window1.xaml.cs private void B ...

随机推荐

  1. wpf ComboBox 获取选中项的文本内容

    一:根据数据源类型获取选中项 类: public class Region { public int REGION_ID { get; set; } public string REGION_CODE ...

  2. 【Oracle】重置参数

    单实例中: alter system reset parameter <scope=memory|spfile|both>: --memory|spfile|both,选其一 集群环境中: ...

  3. C# 时间日期(函数,解释)

    C#时间/日期格式大全,C#时间/日期函数大全 有时候我们要对时间进行转换,达到不同的显示效果 默认格式为:2005-6-6 14:33:34 如果要换成成200506,06-2005,2005-6- ...

  4. VHDL之Aggregate

    Definition A basic operation that combines one or more values into a composite value of a record or ...

  5. C#操作Oracle数据库中文乱码问题解决

    最近公司有一个对外项目,采用的是oracle数据库,以前做的项目基本都是SQLserver,有和oracle对接的也就一些简单的增删查改. 还巧合的遇到乱码问题,网上各种查找,筛选,总算是把问题解决了 ...

  6. RabbitMQ学习之ConntectionFactory与Conntection的认知

    在发送和接收消息重要的类有:ConnectionFactory, Connection,Channel和 QueueingConsumer. ConntectionFactory类是方便创建与AMQP ...

  7. Quartz经典入门案列

    一.Quartz简介 Quartz是一个开放源码项目,专注于任务调度器,提供了极为广泛的特性如持久化任务,集群和分布式任务等.Spring对Quartz的集成与其对JDK Timer的集成在任务.触发 ...

  8. hust 1570 Lazy. Lazy. Laaaaaaaaaaaazy!

    链接 1570 - Lazy. Lazy. Laaaaaaaaaaaazy! 题意 给出三种按键,caplock,shift,nomal(像正常键盘操作一样) ,输入三串字符串,s1,s2,txt, ...

  9. FastFDS常用命令

    1.启停fastdfs相关服务 #start fastdfs  启动服务 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart /usr/loca ...

  10. centos7.XXX配置python3环境

    众做周知,centos 是自带python2.7的.可是随着社会的进步,科技的发展,技术一步步更新换代,python2.7已经不足以满足项目的需求.这时候python3横空出世. 下面跟着我来一起实现 ...