c# winform 鼠标改变窗体的大小,使窗体内的图片跟着改变

C#代码 
  1. //------------------------------------------------------------------------------------------  
  2.   int titleHeight = 0;//标题栏的高度  
  3.   int menuHeight = 0;//菜单栏的高度  
  4.   int stateHeight = 26;//状态栏的高度    
  5.   int taskHeight = 8;//任务栏的高度  
  6.   //------------------------------------------------------------------------------------------  
  7.   
  8.   //改变窗体大小的时候发生,调整窗体大小时让pictureBox1也跟着变化大小  
  9.   private void FormMain_Resize(object sender, EventArgs e)  
  10.   {  
  11.    //MessageBox.Show(Screen.GetWorkingArea(pictureBox1).ToString());//工作区大小  
  12.    //titleHeight = this.Height - this.ClientRectangle.Height;//标题栏的高度   
  13.   
  14.    titleHeight = SystemInformation.CaptionHeight;//获得标题栏高度  
  15.    menuHeight = SystemInformation.MenuHeight;//获得菜单栏高度  
  16.   
  17.    pictureBox1.Width = this.ClientRectangle.Width;//获得当前控件工作区中的矩形的宽,赋给pictureBox1  
  18.    pictureBox1.Height = this.Height - titleHeight - menuHeight - stateHeight - taskHeight;//窗体的高度减去标题栏,菜单栏,状态栏和任务栏的高度,获得当前控件工作区中的矩形的高,赋给pictureBox1  
  19.   }  
posted @ 2009-02-12 14:32  Lester Duo  Views(1275)  Comments(0)    收藏  举报