다음을 통해 공유


Form 클래스

응용 프로그램의 사용자 인터페이스를 구성하는 창 또는 대화 상자를 나타냅니다.

네임스페이스: System.Windows.Forms
어셈블리: System.Windows.Forms(system.windows.forms.dll)

구문

‘선언
<ComVisibleAttribute(True)> _
<ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)> _
Public Class Form
    Inherits ContainerControl
‘사용 방법
Dim instance As Form
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch)] 
public class Form : ContainerControl
[ComVisibleAttribute(true)] 
[ClassInterfaceAttribute(ClassInterfaceType::AutoDispatch)] 
public ref class Form : public ContainerControl
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) */ 
public class Form extends ContainerControl
ComVisibleAttribute(true) 
ClassInterfaceAttribute(ClassInterfaceType.AutoDispatch) 
public class Form extends ContainerControl

설명

Form은 응용 프로그램에 표시되는 모든 창을 나타냅니다. Form 클래스를 사용하여 표준 창, 도구 창, 테두리가 없는 창 및 부동 창을 만들 수 있습니다. 또한 Form 클래스를 사용하여 대화 상자와 같은 모달 창을 만들 수도 있습니다. 특수한 종류의 폼인 MDI(다중 문서 인터페이스) 폼에는 MDI 자식 폼이라고 하는 다른 폼이 포함될 수 있습니다. MDI 폼은 IsMdiContainer 속성을 true로 설정하여 만들고, MDI 자식 폼은 MdiParent 속성을 자식 폼이 포함될 MDI 부모 폼으로 설정하여 만듭니다.

Form 클래스에서 사용할 수 있는 속성을 사용하여, 만들고 있는 대화 상자나 창의 모양, 크기, 색 및 창 관리 기능을 결정할 수 있습니다. Text 속성을 사용하면 제목 표시줄에 창의 캡션을 지정할 수 있습니다. SizeDesktopLocation 속성을 사용하면 창이 표시될 때의 크기와 위치를 정의할 수 있습니다. ForeColor 색 속성을 사용하면 폼에 배치되는 모든 컨트롤의 기본 전경색을 변경할 수 있습니다. FormBorderStyle, MinimizeBoxMaximizeBox 속성을 사용하면 런타임에 폼을 최소화하거나 최대화하거나 크기 조정할 수 있는지 여부를 제어할 수 있습니다.

이러한 속성 외에도 클래스의 메서드를 사용하여 폼을 조작할 수 있습니다. 예를 들어, ShowDialog 메서드를 사용하면 폼을 모달 대화 상자로 표시할 수 있고, SetDesktopLocation 메서드를 사용하면 데스크톱에 폼을 배치할 수 있습니다.

Form 클래스의 이벤트를 사용하면 폼에서 수행되는 동작에 응답할 수 있습니다. Activated 이벤트를 사용하여 폼이 활성화될 때 폼의 컨트롤에 표시되는 데이터를 업데이트하는 등의 작업을 수행할 수 있습니다.

클래스에 Main 메서드를 배치하여 폼을 응용 프로그램의 시작 클래스로 사용할 수 있습니다. Main 메서드에 폼을 만들고 표시하는 코드를 추가합니다. 또한 폼을 실행하기 위해 STAThread 특성을 Main 메서드에 추가해야 합니다. 시작 폼이 닫히면 응용 프로그램도 닫힙니다.

예제

다음 코드 예제에서는 Form의 새 인스턴스를 만들고 ShowDialog 메서드를 호출하여 해당 폼을 대화 상자로 표시합니다. 이 예제에서는 FormBorderStyle, AcceptButton, CancelButton, MinimizeBox, MaximizeBoxStartPosition 속성을 설정하여 폼의 모양 및 기능을 대화 상자로 변경합니다. 또한 폼의 Controls 컬렉션에 있는 Add 메서드를 사용하여 두 개의 Button 컨트롤을 추가합니다. 그런 다음 HelpButton 속성을 사용하여 대화 상자의 캡션 표시줄에 도움말 단추를 표시합니다.

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 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()
End Sub
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();
}
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 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();
   }
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.set_Text("OK");

    // Set the position of the button on the form.
    button1.set_Location(new Point(10, 10));

    // Set the text of button2 to "Cancel".
    button2.set_Text("Cancel");

    // Set the position of the button based on the location of button1.
    button2.set_Location(new Point(button1.get_Left(), 
        button1.get_Height() + button1.get_Top() + 10));

    // Set the caption bar text of the form.   
    form1.set_Text("My Dialog Box");

    // Display a help button on the form.
    form1.set_HelpButton(true);

    // Define the border style of the form to a dialog box.
    form1.set_FormBorderStyle(get_FormBorderStyle().FixedDialog);

    // Set the MaximizeBox to false to remove the maximize box.
    form1.set_MaximizeBox(false);

    // Set the MinimizeBox to false to remove the minimize box.
    form1.set_MinimizeBox(false);

    // Set the accept button of the form to button1.
    form1.set_AcceptButton(button1);

    // Set the cancel button of the form to button2.
    form1.set_CancelButton(button2);

    // Set the start position of the form to the center of the screen.
    form1.set_StartPosition(FormStartPosition.CenterScreen);

    // Add button1 to the form.
    form1.get_Controls().Add(button1);

    // Add button2 to the form.
    form1.get_Controls().Add(button2);

    // Display the form as a modal dialog box.
    form1.ShowDialog();
} //CreateMyForm

상속 계층 구조

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.Control
         System.Windows.Forms.ScrollableControl
           System.Windows.Forms.ContainerControl
            System.Windows.Forms.Form
               파생 클래스

스레드로부터의 안전성

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

Form 멤버
System.Windows.Forms 네임스페이스