C# WinForm 關於表單最大化時的是否全屏效果與是否遮蓋工作列

來源:互聯網
上載者:User

0.建立表單 及添加按鈕

1.
  執行如下按鈕事件
  private void btnFormMax_Click(object sender, EventArgs e)
  {
     if (this.WindowState == FormWindowState.Maximized)
     {
         this.WindowState = FormWindowState.Normal;
     }
     else
     {
         this.WindowState = FormWindowState.Maximized;
     }
  }
  表單最大化時 非全屏 不會遮蓋工作列
  此時this.FormBorderStyle 預設為 Sizable

2.
  執行如下按鈕事件
  private void btnFormMax_Click(object sender, EventArgs e)
  {
      if (this.WindowState == FormWindowState.Maximized)
      {        
         this.WindowState = FormWindowState.Normal;
      }
      else
      {
         this.FormBorderStyle = FormBorderStyle.None;
         this.WindowState = FormWindowState.Maximized;
      }
   }

  表單最大化時 會全屏 及遮蓋工作列
  此時this.FormBorderStyle 為 None 不會顯示表單標題列等相關

3.
  執行如下按鈕事件
  private void btnFormMax_Click(object sender, EventArgs e)
  {
      if (this.WindowState == FormWindowState.Maximized)
      {        
         this.WindowState = FormWindowState.Normal;
      }
      else
      {
         this.FormBorderStyle = FormBorderStyle.None;
         this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
         this.WindowState = FormWindowState.Maximized;
      }
   }

  表單最大化時 非全屏 不會遮蓋工作列
  此時this.FormBorderStyle 為 None 不會顯示表單標題列等相關

[轉]表單最大化的時候,如何指定表單的位置、大小(C#) http://www.cnblogs.com/adandelion/archive/2008/04/03/1136198.html 
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//擷取視窗的標準標題列地區的高度(以象素為單位)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.