Form.FormBorderStyle 属性

定义

获取或设置窗体的边框样式。

C#
public System.Windows.Forms.FormBorderStyle FormBorderStyle { get; set; }

属性值

FormBorderStyle

FormBorderStyle,表示要为窗体显示的边框样式。 默认值为 FormBorderStyle.Sizable

例外

指定值不在有效值范围内。

示例

以下示例创建一 Form 个新实例,并调用该方法 ShowDialog 以对话框形式显示窗体。 本示例将窗体的外观和功能更改为对话框的属性FormBorderStyleMaximizeBoxAcceptButtonMinimizeBoxCancelButtonStartPosition。 该示例还使用 Add 窗体 Controls 集合的方法添加两 Button 个控件。 该示例使用 HelpButton 该属性在对话框的标题栏中显示帮助按钮。

C#
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();
}

注解

窗体的边框样式确定窗体的外部边缘的显示方式。 除了更改窗体的边框显示之外,某些边框样式还阻止窗体调整大小。 例如,边框样式将 FormBorderStyle.FixedDialog 窗体的边框更改为对话框的边框,并阻止调整窗体的大小。 边框样式还会影响窗体标题栏部分的大小或可用性。

备注

使用Sizable样式时,即使已设置为ControlBoxfalse零长度字符串,也无法将窗口大小调整为Text特定最小值。 请考虑改用 SizableToolWindow 样式来解决此问题。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

另请参阅