winform 窗体最大化 分类: WinForm ...

1:窗体首次加载时最大化

(1):主窗体            

            this.WindowState = FormWindowState.Maximized;

           //窗体显示中间部分,不显示窗体名称和最小化、最大化、关闭按钮
            this.FormBorderStyle = FormBorderStyle.None;

            this.WindowState = FormWindowState.Maximized;

(2):子窗体

            设置父窗体的属性:IsMdiContainer=True

            Form f = new Form();
            f.MdiParent = this;

      f.WindowState = FormWindowState.Maximized;


[]窗体最大化的时候,如何指定窗体的位置、大小(C#)


using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Text; 
using System.Windows.Forms; 
namespace WindowsApplication1 

public partial class FormRegion : Form. 

private const long WM_GETMINMAXINFO = 0x24; 
public struct POINTAPI 

public int x; 
public int y; 

public struct MINMAXINFO 

public POINTAPI ptReserved; 
public POINTAPI ptMaxSize; 
public POINTAPI ptMaxPosition; 
public POINTAPI ptMinTrackSize; 
public POINTAPI ptMaxTrackSize; 

public FormRegion() 

InitializeComponent(); 
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); 

protected override void WndProc(ref System.Windows.Forms.Message m) 

base.WndProc(ref m); 
if (m.Msg == WM_GETMINMAXINFO) 

MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO)); 
mmi.ptMinTrackSize.x = this.MinimumSize.Width; 
mmi.ptMinTrackSize.y = this.MinimumSize.Height; 
if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0) 

mmi.ptMaxTrackSize.x = this.MaximumSize.Width; 
mmi.ptMaxTrackSize.y = this.MaximumSize.Height; 

mmi.ptMaxPosition.x = 1; 
mmi.ptMaxPosition.y = 1; 
System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true); 



}  

MessageBox.Show("当前窗体标题栏高度"+(this.Height - this.ClientRectangle.Height).ToString());//获得当前窗体标题栏高度 
ClientRectangle//
获取表示控件的工作区的矩形 
MessageBox.Show(SystemInformation.PrimaryMonitorSize.ToString()); //
获取主显示器屏幕的尺寸(像素
//
获取主显示器当前当前视频模式的尺寸(以象素为单位
MessageBox.Show("
菜单栏高度"+SystemInformation.MenuHeight.ToString()); //获取标准菜单栏的高度 
MessageBox.Show("
标题栏高度"+SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的高度 
MenuHeight//
获取一个菜单行的高度(以象素为单位
CaptionHeight//
获取窗口的标准标题栏区域的高度(以象素为单位)


当前的屏幕除任务栏外的工作域大小
    this.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
    this.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;

当前的屏幕包括任务栏的工作域大小
this.Width=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
this.Height=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;

任务栏大小
this.Width=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width-System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
this.Height=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height-System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;

winform实现全屏显示
WinForm:
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.TopMost = true;  

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/Jackerson/p/4632021.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
自定义窗体最大化、最小化和关闭按钮, C#移动无标题栏窗体的三种代码: C#移动无标题栏窗体的三种代码:第一种采用,需注意窗体上的控件是否把窗体覆盖了。。。MouseDown、MouseMove、MouseUp事件应该是鼠标所处位置最顶层的控件的事件 在窗体的类中声明两个变量 private Point mouseOffset; //记录鼠标指针的坐标 private bool isMouseDown = false; //记录鼠标按键是否按下 创建该窗体 MouseDown、MouseMove、MouseUp事件的相应处理程序 private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X ; yOffset = -e.Y ; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X, mouseOffset.Y); Location = mousePos; } } private void Form1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动,才移动窗体 if (e.Button == MouseButtons.Left) { isMouseDown = false; } } 第二种调用API 未验证 using System.Runtime.InteropServices; [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; private void Form1_MouseDown(object sender, MouseEventArgs e) { ReleaseCapture(); SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0); } 第三种未验证 private bool isMouseDown = false; private Point FormLocation; //form的location private Point mouseOffset; //鼠标的按下位置 [DllImport("user32.dll")] public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); private const int WM_SYSCOMMAND = 0x0112;//点击窗口左上角那个图标的系统信息 private const int SC_MOVE = 0xF010;//移动信息 private const int HTCAPTION = 0x0002;//表示鼠标在窗口标题栏的系统信息 private const int WM_NCHITTEST = 0x84;//鼠标在窗体客户区(除了标题栏和边框以外的部分)发送的消息 private const int HTCLIENT = 0x1;//表示鼠标在窗口客户区的系统消息 private const int SC_MAXIMIZE = 0xF030;//最大化信息 private const int SC_MINIMIZE = 0xF020;//最小化信息 protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if (m.WParam == (IntPtr)SC_MAXIMIZE) { m.WParam = (IntPtr)SC_MINIMIZE; } break; case WM_NCHITTEST: //如果鼠标移动或单击 base.WndProc(ref m);//调用基类的窗口过程——WndProc方法处理这个消息 if (m.Result == (IntPtr)HTCLIENT)//如果返回的是HTCLIENT { m.Result = (IntPtr)HTCAPTION;//把它改为HTCAPTION return;//直接返回退出方法 } break; } base.WndProc(ref m);//如果不是鼠标移动或单击消息就调用基类的窗口过程进行处理 } private void Form1_Load(object sender, EventArgs e) { } ------------------------------- 如何在窗体标题栏左边的控制菜单加入自己的菜单啊? 我们一般在窗口标题栏点右键 或 按Alt+空格 可以弹出那个菜单。 ------解决方案-------------------- using System.Runtime.InteropServices; [DllImport( "user32.dll ")] public static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert); [DllImport( "user32.dll ")] public static extern bool InsertMenu(IntPtr hMenu, uint uPosition, uint uFlags, uint uIDNewItem, string lpNewItem); public const int MF_BYCOMMAND = 0; public const int MF_STRING = 0; public const int MF_BYPOSITION = 0x400; public const int MF_SEPARATOR = 0x800; private const uint SC_ABOUT = 0x0001; public const int WM_SYSCOMMAND = 0x0112; private void Form1_Load(object sender, EventArgs e) { IntPtr vMenuHandle = GetSystemMenu(Handle, false); InsertMenu(vMenuHandle, 255, MF_STRING, SC_ABOUT, "About... "); } protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_SYSCOMMAND: if ((uint)m.WParam == SC_ABOUT) { MessageBox.Show( "Zswang 路过! "); } break; } base.WndProc(ref m); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值