adandelion

诗词在线 http:/www.chinapoesy.com


诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|现代诗歌

博客园 首页 联系 订阅 管理

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


(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);

郁闷啊。后来在MSND上找到了
http://support.microsoft.com/?scid=kb%3Ben-us%3B327824&x=10&y=14  这才算解决了。




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);
            }

        }

    }

}


posted on 2008-04-03 14:06  猪头  阅读(4964)  评论(0编辑  收藏  举报

欢迎访问诗词在线http://www.chinapoesy.com   诗词在线 |唐诗|宋词|元曲|诗经|离骚|乐府|古典诗歌|现代诗歌|古典诗词|现代诗词|诗歌可以陶冶你的情操、丰富你的生活,让你更具内涵。诗词在线打造中国最好的诗词社区!

诗词在线社区

126在线阅读网 历史书籍、文学书籍、小说。。。