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



    窗体最大化的时候,如何指定窗体的位置、大小(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);
                }

            }

        }

    }


  • 相关阅读:
    HDU 5583 Kingdom of Black and White 水题
    HDU 5578 Friendship of Frog 水题
    Codeforces Round #190 (Div. 2) E. Ciel the Commander 点分治
    hdu 5594 ZYB's Prime 最大流
    hdu 5593 ZYB's Tree 树形dp
    hdu 5592 ZYB's Game 树状数组
    hdu 5591 ZYB's Game 博弈论
    HDU 5590 ZYB's Biology 水题
    cdoj 1256 昊昊爱运动 预处理/前缀和
    cdoj 1255 斓少摘苹果 贪心
  • 原文地址:https://www.cnblogs.com/adandelion/p/1136198.html
Copyright © 2020-2023  润新知