Winform WPF 窗体显示位置
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 窗体显示位置的更多相关文章
- WinForm 设置窗体启动位置在活动屏幕右下角
WinForm 设置窗体启动位置在活动屏幕右下角 在多屏幕环境下, 默认使用鼠标所在的屏幕 1. 设置窗体的 StartPosition 为 FormStartPosition.Manual. 2. ...
- WinForm开发,窗体显示和窗体传值相关知识总结
主窗体中代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void b ...
- WPF 窗体显示最前端
原文:WPF 窗体显示最前端 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/jjx0224/article/details/8782845 如何做一 ...
- Winform将一个窗体显示在另一个窗体中
private void ShowForm(Form Indexform) { Form1 form1 = new Form1(); form1 .TopLevel = false; form1 .P ...
- WPF C# 多屏情况下,实现窗体显示到指定的屏幕内
原文:WPF C# 多屏情况下,实现窗体显示到指定的屏幕内 针对于一个程序,需要在两个显示屏上显示不同的窗体,(亦或N个显示屏N个窗体),可以使用如下的方式实现. 主要涉及到的:System.Wind ...
- 【转】WinForm窗体显示和窗体间传值
以前对WinForm窗体显示和窗体间传值了解不是很清楚 最近做了一些WinForm项目,把用到的相关知识整理如下 A.WinForm中窗体显示 显示窗体可以有以下2种方法: Form.ShowDial ...
- C#:控制WinForm界面的显示
控制WinForm界面在屏幕的四个角落显示,具体代码中有说明: using System; using System.Collections.Generic; using System.Drawing ...
- Winform窗口弹出位置控制
窗体的弹出位置可以由属性StartPosition来指定,默认值有: Manural 自定义,由属性Location指定: CenterScreen 屏幕中央: WindowsDefaultBound ...
- WPF用ShowDialog()弹出窗体时控制该窗体的显示位置,并传值回父窗体
原文:http://blog.csdn.net/kiss0622/article/details/5852153 方法一: 1.父窗口代码 Window1.xaml.cs private void B ...
随机推荐
- PowerDesigner 逆向工程Non SQL Error : Could not load class com.mysql.jdbc.Driver
建立与数据库的连接. 在菜单条上,有一个Database的选择项: 选择connect…后弹出设置对话框: 在Data source里选择第三个单选按钮,即Connection profile:后,点 ...
- Django mysql 改用pymysql 驱动
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', #数据库引擎 'NAME': 'test', #数据库名 'USER' ...
- Boost锁~临界区保护和临界资源共享
前言: 除了thread,boost::thread另一个重要组成部分是mutex,以及工作在mutex上的boost::mutex::scoped_lock.condition和barrier,这些 ...
- 给 iOS 开发者的 RxSwift(一)
RxSwift 或许我们都听说过,但或许只知道 RxSwift 这个单词,长篇大论关于 RxSwift 的介绍往往使读者迷失在各种概念当中,却不知如何让它大展伸手.或许我们可以换一种姿势,一些应用场景 ...
- div与div之间的拖拽
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- python编写简单的html登陆页面(3)
1 在python编写简单的html登陆页面(2)的基础上在延伸一下: 可以将静态分配数据,建立表格,存放学生信息 2 加载到静态数据 3 html的编写直接在表格里添加一组数据就行了 4 V ...
- 【disconf】环境搭建【linux】
1.搭建disconf需要安装的配置. 安装Linux:CentOS7 安装Zookeeper:zookeeper-3.4.6 安装Redis:redis-3.0.0 安装N ...
- Codeforces Round #471 (Div. 2)A. Feed the cat
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another ...
- Tab 切换效果
今天写的两个小效果都是为了测试我写的单参函数,结果还是有点成功的~~此处是不是想发表情包! Tab效果很简单,这里我就不赘述了,直接上代码: html代码: <div class="c ...
- [bzoj 2726] 任务安排 (斜率优化 线性dp)
3月14日第三题!!!(虽然是15号发的qwq) Description 机器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3-N.这N个任务被分成若干批 ...