当前位置:IT168首页 > 技术开发 > 概述
[收藏此页] [打印] [推荐] [评论]

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

责任编辑:nancy作者:ITPUB论坛   2008-05-20   
文本Tag: 微软 sql

【IT168技术文档】

  1)使用窗体默认的最大化方法
  this.WindowState = FormWindowState.Maximized 发现窗体的位置x和y都是小于零的。设置了 this.Location = new Point(1, 1);后仍然无效。。。 



  2)设置了窗体的最大值后,测试发现有时候(窗体宽度接近屏幕的宽度的时候),窗体的高度的设置是无效的。
  this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
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); } } } }
上一页
1
下一页
收藏到: 添加到“百度搜藏”添加到“QQ书签”添加到“Google书签”添加到“Yahoo收藏”添加到“和讯网摘”
【内容导航】
本文欢迎转载,转载请注明:转载自IT168 [ http://www.it168.com/ ]
本文链接:http://tech.it168.com/d/2008-05-20/200805200834856.shtml
技术开发相关文章   .net server SQL 微软
  • 暂无
友情推介