Assembly : System.Windows.Forms (dans system.windows.forms.dll)
Syntaxe<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
NotesForm est une représentation de n'importe quelle fenêtre affichée dans votre application. La classe Form peut être utilisée pour créer les fenêtres standard, Outil, sans bord et flottantes. Vous pouvez également utiliser la classe Form pour créer des fenêtres modales telles qu'une boîte de dialogue. Un type spécial de formulaire, le formulaire d'interface multidocument (MDI, Multiple Document Interface), peut contenir d'autres formulaires appelés formulaires enfants MDI. Un formulaire MDI est créé par l'affectation de la valeur true à la propriété IsMdiContainer. Les formulaires enfants MDI sont créés par l'affectation à la propriété MdiParent de la valeur du formulaire parent MDI qui contient le formulaire enfant.
À l'aide des propriétés disponibles dans la classe Form, vous pouvez déterminer les fonctionnalités de gestion de l'apparence, de la taille, de la couleur et de la fenêtre de la fenêtre ou de la boîte de dialogue que vous créez. La propriété Text vous permet de spécifier la légende de la fenêtre dans la barre de titre. Les propriétés Size et DesktopLocation vous permettent de définir la taille et la position de la fenêtre. Vous pouvez utiliser la propriété de couleur ForeColor pour modifier la couleur de premier plan par défaut de tous les contrôles placés sur le formulaire. Les propriétés FormBorderStyle, MinimizeBox et MaximizeBox vous permettent de contrôler si le formulaire peut être réduit, agrandi ou redimensionné au moment de l'exécution.
Outre les propriétés, vous pouvez utiliser les méthodes de la classe pour manipuler un formulaire. Par exemple, vous pouvez utiliser la méthode ShowDialog pour afficher un formulaire comme une boîte de dialogue modale. Vous pouvez utiliser la méthode SetDesktopLocation pour positionner le formulaire sur le bureau.
Les événements de la classe Form vous permettent de répondre aux actions exécutées sur le formulaire. Vous pouvez utiliser l'événement Activated pour exécuter des opérations telles que la mise à jour des données affichées dans les contrôles du formulaire lorsque celui-ci est activé.
Vous pouvez utiliser un formulaire comme classe initiale dans votre application en plaçant une méthode appelée Main dans la classe. Dans la méthode Main, ajoutez le code pour créer et afficher le formulaire. Vous devez également ajouter l'attribut STAThread à la méthode Main dans l'ordre pour exécuter le formulaire. Lorsque le formulaire initial est fermé, l'application est fermée également.
ExempleL'exemple de code suivant crée une nouvelle instance de Form et appelle la méthode ShowDialog pour afficher le formulaire sous la forme d'une boîte de dialogue. Cet exemple définit les propriétés FormBorderStyle, AcceptButton, CancelButton, MinimizeBox, MaximizeBox et StartPosition pour transformer le formulaire en boîte de dialogue sur le plan de l'apparence et des fonctionnalités. Il utilise par ailleurs la méthode Add de la collection Controls du formulaire pour ajouter deux contrôles Button. Il emploie en outre la propriété HelpButton pour afficher un bouton d'aide dans la barre de légende de la boîte de dialogue.
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
Sécurité des threads
Plates-formesWindows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition
Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.
Informations de version
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ