C#控制台窗口居中显示(转)
private struct RECT { public int left, top, right, bottom; }
[DllImport("kernel32.dll", SetLastError = true)]
private static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll", SetLastError = true)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT rc);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool MoveWindow(IntPtr hWnd, int x, int y, int w, int h, bool repaint);
/// <summary>
/// 控制台窗体居中
/// </summary>
public static void SetWindowPositionCenter()
{
IntPtr hWin = GetConsoleWindow();
RECT rc;
GetWindowRect(hWin, out rc);
Screen scr = Screen.FromPoint(new Point(rc.left, rc.top));
int x = scr.WorkingArea.Left + (scr.WorkingArea.Width - (rc.right - rc.left)) / ;
int y = scr.WorkingArea.Top + (scr.WorkingArea.Height - (rc.bottom - rc.top)) / ;
MoveWindow(hWin, x, y, rc.right - rc.left, rc.bottom - rc.top, true);
}
C#控制台窗口居中显示(转)的更多相关文章
- Example005控制弹出窗口居中显示
<!-- 实例005控制弹出窗口居中显示 --> <head> <meta charset="UTF-8"> </head> < ...
- 【Qt】窗口居中显示
w.move((a.desktop()->width() - w.width())/, (a.desktop()->height() - w.height())/); 上述方法可以置中,但 ...
- python之tkinter使用-窗口居中显示
# 窗口居中显示 import tkinter as tk def set_win_center(root, curWidth='', curHight=''): ''' 设置窗口大小,并居中显示 : ...
- Qt 设置窗口居中显示和窗体大小
设置窗口居中显示 方法一:在窗口(QWidget类及派生类)的构造函数中添加如下代码: #include <QDesktopWidget> //....... QDesktopWidget ...
- Java_Swing中让窗口居中显示的方法(三种方法)
方法一: int windowWidth = frame.getWidth(); // 获得窗口宽 int windowHeight = frame.getHeight(); // 获得窗口高 ...
- 设置easyUI-dialog窗口居中显示
默认情况下应该是在屏幕居中显示的.但是有的时候没有居中只要重新纠正下就可以了 $('#add_dialog').dialog('open'); //打开添加对话框 $('#add_dialog').w ...
- C# 控制台窗口的显示与隐藏
1. 定义一个Consolse帮助类,如下: /// <summary> /// 控制台帮助类 /// </summary> public static class Conso ...
- 让div自适应浏览器窗口居中显示
今天做 banner 时发现一个问题,就是浏览器窗口水平拉伸时 banner 图未能居中,所以网上找了些资料,自己写了个小 demo html代码: <div class="div1& ...
- newWindow 弹出的新窗口居中显示
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
随机推荐
- HTTP 请求未经客户端身份验证方案“Anonymous”授权。
今天调取WebService的时候报: HTTP 请求未经客户端身份验证方案“Anonymous”授权. 解决办法: 配置文件里改: <basicHttpBinding> <bind ...
- 复习js
js写在页面最后如果放在前面,需要加window.onload=function(){)常见的两种输出方式 在网页中弹出显示框,显示信息 alert() 在控制台输出消息,一般用来调试程序consol ...
- 源码分析七(java.lang包之IllegalArgumentException类)
一:IllegalArgumentException非法参数类,这个类继承父类RuntimeException public class IllegalArgumentException extend ...
- Linux Shell 通配符、元字符、转义符使用实例介绍
https://www.cnblogs.com/chengmo/archive/2010/10/17/1853344.html
- c#系统消息类封装
今天封装了一个返回json的消息类 using System; using System.Collections.Generic; using System.Linq; using System.Te ...
- create a cocos2d-x-3.0 project in Xcode
STEP1: Open Terminal SETP2: Run setup.py SETP3: Run source /Users/your_user/.bash_profile( so that e ...
- 恶劣条件下的apache配置(Linux)
(本文出自yangjj ^_^) 前提:1.没联网,yum挂.2.至少要有GCC,要不玩个屁. 3.你有充足的咖啡并且有几个小时时间不想打dota. 4.你要做集群. 以上条件不满足其一,看到这里 ...
- javascript 以“年-月-日 时:分:秒”格式显示当前时间
运行代码 /** * Created by shgbit on 2015/1/9. *js代码 */ function showNow(){ var t=new Date(); var mont ...
- ASP正则匹配方法
方法二:找到匹配的进行替换 ip="127.0.0.1" Function ReplaceTest(str,patrn, replStr) Dim regEx, str1 Set ...
- 使用 requests 进行身份认证
如下图,有些网站需要使用用户名密码才可以登录,我们可以使用 requests 的 auth 参数来实现 import requests req = requests.get("http:// ...