Assembly : System.Windows.Forms (dans system.windows.forms.dll)
SyntaxePublic NotInheritable Class Application
Dim instance As Application
public sealed class Application
public ref class Application sealed
public final class Application
public final class Application
NotesLa classe Application possède des méthodes permettant de démarrer et d'arrêter des applications et des threads et de traiter des messages Windows, comme suit :
-
Run démarre une boucle de messages d'application sur le thread en cours et, éventuellement, affiche un formulaire.
-
Exit ou ExitThread arrête une boucle de message.
-
DoEvents traite des messages alors que votre programme est en boucle.
-
AddMessageFilter ajoute un filtre de message à la pompe de messages d'application afin de surveiller les messages Windows.
-
IMessageFilter vous permet d'empêcher le déclenchement d'un événement ou d'effectuer des opérations spéciales avant d'appeler un gestionnaire d'événements.
Cette classe possède des propriétés CurrentCulture et CurrentInputLanguage permettant d'obtenir ou de définir des informations sur la culture du thread en cours.
Vous ne pouvez pas créer une instance de cette classe.
ExempleL'exemple de code suivant illustre l'énumération de numéros dans une zone de liste d'un formulaire. Chaque fois que vous cliquez sur button1, l'application ajoute un autre numéro à la liste.
La méthode Main appelle Run pour démarrer l'application, créant ainsi le formulaire listBox1 et button1. Lorsque l'utilisateur clique sur button1, la méthode button1_Click affiche MessageBox. S'il clique sur No dans MessageBox, la méthode button1_Click ajoute un numéro à la liste. Si l'utilisateur clique sur Yes, l'application appelle alors Exit pour traiter tous les messages restants dans la file d'attente, puis s'arrêter.
Remarque |
|---|
| L'appel à Exit échoue en cas de niveau de confiance partiel. |
Public Class Form1 Inherits Form <STAThread()> _ Shared Sub Main() ' Start the application. Application.Run(New Form1) End Sub Private WithEvents button1 As Button Private WithEvents listBox1 As ListBox Public Sub New() button1 = New Button button1.Left = 200 button1.Text = "Exit" listBox1 = New ListBox Me.Controls.Add(button1) Me.Controls.Add(listBox1) End Sub Private Sub button1_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles button1.Click Dim count As Integer = 1 ' Check to see whether the user wants to exit the application. ' If not, add a number to the list box. While (MessageBox.Show("Exit application?", "", _ MessageBoxButtons.YesNo) = DialogResult.No) listBox1.Items.Add(count) count += 1 End While ' The user wants to exit the application. ' Close everything down. Application.Exit() End Sub End Class
public class Form1 : Form { [STAThread] public static void Main() { // Start the application. Application.Run(new Form1()); } private Button button1; private ListBox listBox1; public Form1() { button1 = new Button(); button1.Left = 200; button1.Text = "Exit"; button1.Click += new EventHandler(button1_Click); listBox1 = new ListBox(); this.Controls.Add(button1); this.Controls.Add(listBox1); } private void button1_Click(object sender, System.EventArgs e) { int count = 1; // Check to see whether the user wants to exit the application. // If not, add a number to the list box. while (MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo)==DialogResult.No) { listBox1.Items.Add(count); count += 1; } // The user wants to exit the application. // Close everything down. Application.Exit(); } }
public ref class Form1: public System::Windows::Forms::Form { private: Button^ button1; ListBox^ listBox1; public: Form1() { button1 = gcnew Button; button1->Left = 200; button1->Text = "Exit"; button1->Click += gcnew EventHandler( this, &Form1::button1_Click ); listBox1 = gcnew ListBox; this->Controls->Add( button1 ); this->Controls->Add( listBox1 ); } private: void Form1::button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) { int count = 1; // Check to see whether the user wants to exit // the application. If not, add a number to the list box. while ( MessageBox::Show( "Exit application?", "", MessageBoxButtons::YesNo ) == ::DialogResult::No ) { listBox1->Items->Add( count ); count += 1; } // The user wants to exit the application. // Close everything down. Application::Exit(); } }; int main() { // Starts the application. Application::Run( gcnew Form1 ); }
public class Form1 extends Form { /** @attribute STAThread() */ public static void main(String[] args) { // Start the application. Application.Run(new Form1()); } //main private Button button1; private ListBox listBox1; public Form1() { button1 = new Button(); button1.set_Left(200); button1.set_Text("Exit"); button1.add_Click(new EventHandler(button1_Click)); listBox1 = new ListBox(); this.get_Controls().Add(button1); this.get_Controls().Add(listBox1); } //Form1 public void button1_Click(Object sender, System.EventArgs e) { int count = 1; // Check to see whether the user wants to exit the application. // If not, add a number to the list box. while ((MessageBox.Show("Exit application?", "", MessageBoxButtons.YesNo).Equals(get_DialogResult().No))) { listBox1.get_Items().Add(new Integer(count)); count += 1; } // The user wants to exit the application. // Close everything down. Application.Exit(); } //button1_Click } //Form1
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
Remarque
Outils (masquer)
S'enregistrer
Liste des Membres
Qui est en ligne?
FAQ