Form.StartPosition Property

Definition

런타임에 폼의 시작 위치를 가져오거나 설정합니다.Gets or sets the starting position of the form at run time.

public:
 property System::Windows::Forms::FormStartPosition StartPosition { System::Windows::Forms::FormStartPosition get(); void set(System::Windows::Forms::FormStartPosition value); };
public System.Windows.Forms.FormStartPosition StartPosition { get; set; }
member this.StartPosition : System.Windows.Forms.FormStartPosition with get, set
Public Property StartPosition As FormStartPosition

Property Value

FormStartPosition

폼의 시작 위치를 나타내는 FormStartPosition입니다.A FormStartPosition that represents the starting position of the form.

Exceptions

지정 된 값의 유효한 값 범위를 벗어납니다.The value specified is outside the range of valid values.

Examples

다음 예에서는 Form의 새 인스턴스를 만들고 ShowDialog 메서드를 호출 하 여 폼을 대화 상자로 표시 합니다.The following example creates a new instance of a Form and calls the ShowDialog method to display the form as a dialog box. 이 예에서는 FormBorderStyle, AcceptButton, CancelButtonStartPosition 속성을 설정 하 여 양식의 모양과 기능을 대화 상자로 변경 합니다.The example sets the FormBorderStyle, AcceptButton, CancelButton, and StartPosition properties to change the appearance and functionality of the form to a dialog box. 또한이 예제에서는 폼의 Controls 컬렉션의 Add 메서드를 사용 하 여 두 개의 Button 컨트롤을 추가 합니다.The example also uses the Add method of the form's Controls collection to add two Button controls. 이 예제에서는 HelpButton 속성을 사용 하 여 대화 상자의 캡션 표시줄에 도움말 단추를 표시 합니다.The example uses the HelpButton property to display a help button in the caption bar of the dialog box.

public:
   void CreateMyForm()
   {
      // Create a new instance of the form.
      Form^ form1 = gcnew Form;
      // Create two buttons to use as the accept and cancel buttons.
      Button^ button1 = gcnew Button;
      Button^ button2 = gcnew Button;
      
      // Set the text of button1 to "OK".
      button1->Text = "OK";
      // Set the position of the button on the form.
      button1->Location = 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
         = 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 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();
   }
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 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();
 }
 
Public Sub CreateMyForm()
    ' Create a new instance of the form.
    Dim form1 As New Form()
    ' Create two buttons to use as the accept and cancel buttons.
    Dim button1 As New Button()
    Dim button2 As 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 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()
End Sub

Remarks

이 속성을 사용 하면 런타임에 표시 되 면 폼의 시작 위치를 설정할 수 있습니다.This property enables you to set the starting position of the form when it is displayed at run time. Location 속성을 설정 하거나 Windows에서 지정한 기본 위치를 사용 하 여 폼의 위치를 수동으로 지정할 수 있습니다.The form's position can be specified manually by setting the Location property or use the default location specified by Windows. 또한 다중 문서 MDI (인터페이스) 자식 폼과 같은 폼의 부모 폼의 가운데 또는 화면 가운데에 표시 하려면 폼을 배치할 수 있습니다.You can also position the form to display in the center of the screen or in the center of its parent form for forms such as multiple-document interface (MDI) child forms.

이 속성은 폼 표시 되기 전에 설정 되어야 합니다.This property should be set before the form is shown. Show 또는 ShowDialog 메서드나 폼의 생성자에서 호출 하기 전에이 속성을 설정할 수 있습니다.You can set this property before you call the Show or ShowDialog method or in your form's constructor.

Applies to

See also