winform窗体置前

1.窗体置前

TopMost=true;

2.窗口最大化,最小化,正常

Me.WindowState   =   FormWindowState.Maximized           Me.WindowState   =   FormWindowState.Maximized           Me.WindowState   =   FormWindowState.Normal

 

3.窗体
     

1.ITPUB个人空间w0@ Li LR1x+Z1P
  执行如下按钮事件
2R�z'zMR4TL0  private void btnFormMax_Click(object sender, EventArgs e)
${{3E kdF.mv:D0  {ITPUB个人空间 x7wy%L0}2e
     if (this.WindowState == FormWindowState.Maximized)
-qL {6E*Z%tu0     {
7C MK4jk:E0         this.WindowState = FormWindowState.Normal;ITPUB个人空间P:Y9o+J1jfI#\
     }
5S-t(n'Tq@0     else
or}[ W{0     {ITPUB个人空间*a D"k? Ow
         this.WindowState = FormWindowState.Maximized;
BV"x-pPuBU0     }
L.paY-]c$d0  }ITPUB个人空间.X'o!T}/{,x(|
  窗体最大化时 非全屏 不会遮盖任务栏ITPUB个人空间'h Q2eyS.c;S
  此时this.FormBorderStyle. 默认为 Sizable

2.ITPUB个人空间 {,OJA;T8w:~
  执行如下按钮事件ITPUB个人空间aK*||,VL5^
  private void btnFormMax_Click(object sender, EventArgs e)ITPUB个人空间{[!f4~'c3s t(|?D
  {ITPUB个人空间![? NL/T$\
      if (this.WindowState == FormWindowState.Maximized)ITPUB个人空间GK%sSF
      {       
'` {l$H{4h0         this.WindowState = FormWindowState.Normal;ITPUB个人空间sH4wCoWl~
      }ITPUB个人空间0\q:W4b\ OU
      else
,cXBG^7D%yB RQ0      {ITPUB个人空间a2d,pmO5{_$Q8l
         this.FormBorderStyle. = FormBorderStyle.None;ITPUB个人空间3h`.y8|.l_
         this.WindowState = FormWindowState.Maximized;ITPUB个人空间@.?8~5` }gv
      }
7Wm7Ott0   }

  窗体最大化时 会全屏 及遮盖任务栏ITPUB个人空间'w"w1k/Jh$|-zC
  此时this.FormBorderStyle. 为 None 不会显示窗体标题栏等相关

3.ITPUB个人空间`1~lD6T\(\
  执行如下按钮事件
3v@d+M*e)n2d-qX0  private void btnFormMax_Click(object sender, EventArgs e)
]&s]H$m bG Y0  {ITPUB个人空间R0dui+Mr1}9q
      if (this.WindowState == FormWindowState.Maximized)ITPUB个人空间ww B|/n&_'h
      {       ITPUB个人空间F$}&o c9[7@
         this.WindowState = FormWindowState.Normal;
/M OBz3a;H0      }ITPUB个人空间;L'R#tw*~
      else
yW#ZN&c['l_9{*?0      {
ER cd(M0         this.FormBorderStyle. = FormBorderStyle.None;ITPUB个人空间/s7Sb!L,OZ
         this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
%\p|#b%q)P1|({0         this.WindowState = FormWindowState.Maximized;ITPUB个人空间0dX ]0psT
      }ITPUB个人空间9uXE9^IhDKj1q
   }

  窗体最大化时 非全屏 不会遮盖任务栏
0LZue�n0  此时this.FormBorderStyle. 为 None 不会显示窗体标题栏等相关ITPUB个人空间j `4T'bo@%f2P


[转]窗体最大化的时候,如何指定窗体的位置、大小(C#) http://www.cnblogs.com/adandelion/archive/2008/04/03/1136198.htmlITPUB个人空间+i)z~Gxl^�?E Y
using System;ITPUB个人空间4t"YO3['q(U
using System.Collections.Generic;
1W aN#T;sVF6Nr:[l0using System.ComponentModel;ITPUB个人空间+|F g$e8a.Dn
using System.Data;ITPUB个人空间LY5b7KOf.C/g
using System.Drawing;
d;Khc Q;N6L"R?)@2K0using System.Text;
j@sFwVRM9J.f0using System.Windows.Forms;ITPUB个人空间�j `1v\z%{,I^;i
ITPUB个人空间o;m%k4}oW1\0U"f
namespace WindowsApplication1
;T2g*RE8n zp4~$b0{
w1g*?v|5U"y`a0public partial class FormRegion : Form.
0G8pmPM0{ITPUB个人空间8~:\%n:tc(ASkAc
private const long WM_GETMINMAXINFO = 0x24;
cxs;C cNE&{0
&a3@5t0f$FH0public struct POINTAPI
8M0P3}Z@_Z0{ITPUB个人空间7c"g:y-jo;QI:@ ~
public int x;
y%YD7gis {0public int y;ITPUB个人空间a0CJ6j9m;mrx1?
}
|1]?@_3o }0ITPUB个人空间c w:K+Y1cq
public struct MINMAXINFOITPUB个人空间/b,M{)e mq
{ITPUB个人空间 KB Va.Rz Hn
public POINTAPI ptReserved;
aA:YI` h `0public POINTAPI ptMaxSize;
x'DA U0yWF0t*}0public POINTAPI ptMaxPosition;ITPUB个人空间 IuV)J.Vu
public POINTAPI ptMinTrackSize;
*Nm K1MR d$wW@0public POINTAPI ptMaxTrackSize;ITPUB个人空间i ^4Iw[@
}
&v#T�Wd`7n+H c ?0public FormRegion()
4?$}F5XD)u0{ITPUB个人空间O0R8J{7{
InitializeComponent();ITPUB个人空间_$g$Al Ms
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);ITPUB个人空间CH z)A.e%n
}
r'J [la3mM2L0
,jf,M rgEq6cE0
M{�|-j1D7Y0protected override void WndProc(ref System.Windows.Forms.Message m)
\7UD&EO0{
q6]]#d\c$~3E[0base.WndProc(ref m);ITPUB个人空间Qpk#k4YlJ7]
if (m.Msg == WM_GETMINMAXINFO)
8_(^ dpyp'_9q0{ITPUB个人空间|;q0B%X ]%e\2E
MINMAXINFO mmi = (MINMAXINFO)m.GetLParam(typeof(MINMAXINFO));
?et'~!tI-^K0mmi.ptMinTrackSize.x = this.MinimumSize.Width;
R7l`~+y0mmi.ptMinTrackSize.y = this.MinimumSize.Height;ITPUB个人空间Kk T-kI-th(]
if (this.MaximumSize.Width != 0 || this.MaximumSize.Height != 0)
g+g3kZ/F_0{ITPUB个人空间R[o o o9R
mmi.ptMaxTrackSize.x = this.MaximumSize.Width;
5G8d ^l/L0mmi.ptMaxTrackSize.y = this.MaximumSize.Height;
MpH!_J6I0}ITPUB个人空间 uIn�WeT1Q9l
mmi.ptMaxPosition.x = 1;
:Jl-@-fC(z_0mmi.ptMaxPosition.y = 1;ITPUB个人空间%]1w z]!n8s k2B3u

YEJp k3{l(s0System.Runtime.InteropServices.Marshal.StructureToPtr(mmi, m.LParam, true);ITPUB个人空间kC+PH9M`g3d,?
}
$T�F&NV_BJ0}ITPUB个人空间v1YNW�Ii`
}
$z{%P7L/w*RjDC0}   

MessageBox.Show("当前窗体标题栏高度"+(this.Height - this.ClientRectangle.Height).ToString());//获得当前窗体标题栏高度ITPUB个人空间/m/U\ P7RK J

G'Y2T�?xy8[O!I0ClientRectangle//获取表示控件的工作区的矩形
Z]9|5e(f L)?0ITPUB个人空间9aq6Dn$j$?
MessageBox.Show(SystemInformation.PrimaryMonitorSize.ToString()); //获取主显示器屏幕的尺寸(像素)ITPUB个人空间9Ba*tFT*Ww#@0WB
//获取主显示器当前当前视频模式的尺寸(以象素为单位)ITPUB个人空间DB ~7v+Xd,HJ

7zf,X Xv7})`I7k6Y+]E0MessageBox.Show("菜单栏高度"+SystemInformation.MenuHeight.ToString()); //获取标准菜单栏的高度ITPUB个人空间"U.b S/@,f~ f%Z v4N*Q
MessageBox.Show("标题栏高度"+SystemInformation.CaptionHeight.ToString()); //获取标准标题栏的高度
i+S7Bh%n7J(v"d6U0ITPUB个人空间%gk Kn0llPmk
MenuHeight//获取一个菜单行的高度(以象素为单位)
X wnX$x'F0
]q jE]#x Aa0CaptionHeight//获取窗口的标准标题栏区域的高度(以象素为单位) 


4.按ESC退出窗体

protected override void onKeyPress(System.Windows.Forms.KeyPressEventArgs e)//重写onKeyPress方法
{
if ((int)(byte)e.KeyChar == (int)System.Windows.Forms.Keys.Escape)
this.Close(); // Esc was pressed
//如果按下了ESC退出程序
}


 


   

你可能感兴趣的:(WinForm)