Form控制大小属性

FormBorderStyle :指示窗体的边框和和标题栏的外观和行为。

1.None-->无边框;

2.FixedSingle-->固定的单行边框;

3.Fixed3D-->固定的三维边框;

4.FixedDialog-->固定的对话框样式的粗边框;

5.Sizable-->可调整大小的边框;

6.FixedToolWindow-->不可调整大小的工具窗口边框。工具窗口不会显示在任务栏中也不会显示在当用户按 Alt+Tab 时出现的窗口中。尽管指定 FixedToolWindow 的窗体通常不显示在任务栏中,还是必须确保 ShowInTaskbar 属性设置为 false,因为其默认值为 true;

7.SizableToolWindow-->可调整大小的工具窗口边框。工具窗口不会显示在任务栏中也不会显示在当用户按 Alt+Tab 时出现的窗口中;

public void InitMyForm()
{
	// Adds a label to the form.
	Label label1 = new Label();
	label1.Location = new System.Drawing.Point(80,80);
	label1.Name = "label1";
	label1.Size = new System.Drawing.Size(132,80);
	label1.Text = "Start Position Information";
	this.Controls.Add(label1);

	// Changes the border to Fixed3D.
	FormBorderStyle = FormBorderStyle.Fixed3D;

	// Displays the border information.
	label1.Text = "The border is " + FormBorderStyle;	
}

MaximizeBox:指示是否在窗体的标题栏中显示“最大化”按钮。

MaximumSize:窗体可以调整到的最大大小。

MinimizeBox:指示是否在窗体的标题栏中显示“最小化”按钮。

MinimumSize:窗体可以调整到的最小大小。

public void CreateMyForm()
{
   // Create a new instance of the form.
   Form form1 = new Form();
   // Create two buttons to use as the accept and cancel buttons.
   Button button1 = new Button ();
   Button button2 = new Button ();

   // Set the text of button1 to "OK".
   button1.Text = "OK";
   // Set the position of the button on the form.
   button1.Location = new Point (10, 10);
   // Set the text of button2 to "Cancel".
   button2.Text = "Cancel";
   // Set the position of the button based on the location of button1.
   button2.Location
      = new Point (button1.Left, button1.Height + button1.Top + 10);
   // Set the caption bar text of the form.   
   form1.Text = "My Dialog Box";
   // Display a help button on the form.
   form1.HelpButton = true;

   // Define the border style of the form to a dialog box.
   form1.FormBorderStyle = FormBorderStyle.FixedDialog;
   // Set the MaximizeBox to false to remove the maximize box.
   form1.MaximizeBox = false;
   // Set the MinimizeBox to false to remove the minimize box.
   form1.MinimizeBox = false;
   // Set the accept button of the form to button1.
   form1.AcceptButton = button1;
   // Set the cancel button of the form to button2.
   form1.CancelButton = button2;
   // Set the start position of the form to the center of the screen.
   form1.StartPosition = FormStartPosition.CenterScreen;

   // Add button1 to the form.
   form1.Controls.Add(button1);
   // Add button2 to the form.
   form1.Controls.Add(button2);

   // Display the form as a modal dialog box.
   form1.ShowDialog();
}
固定窗的大小可以将:MaximumSize和MinimumSize设置成同一个数值,然后把MaximizeBox属性设为false,FormBorderStyle的属性设为FixedSingle 。
posted @ 2011-06-23 21:45  Irving314  阅读(3358)  评论(0编辑  收藏  举报