Cursor, classe (System.Windows.Forms)

Bibliothèque de classes .NET Framework 
Cursor, classe 

Représente l'image utilisée pour peindre le pointeur de souris.

Espace de noms : System.Windows.Forms
Assembly : System.Windows.Forms (dans system.windows.forms.dll)

SyntaxeSyntaxe


Visual Basic (Déclaration)
<SerializableAttribute> _
Public NotInheritable Class Cursor
    Implements IDisposable, ISerializable


Visual Basic (Utilisation)
Dim instance As Cursor


C#
[SerializableAttribute] 
public sealed class Cursor : IDisposable, ISerializable


C++
[SerializableAttribute] 
public ref class Cursor sealed : IDisposable, ISerializable


J#
/** @attribute SerializableAttribute() */ 
public final class Cursor implements IDisposable, ISerializable


JScript
SerializableAttribute 
public final class Cursor implements IDisposable, ISerializable
NotesNotes

Un curseur est une petite image dont l'emplacement à l'écran est contrôlé par un dispositif de pointage, tel qu'une souris, un stylet ou un trackball. Quand l'utilisateur déplace le dispositif de pointage, le système d'exploitation déplace le curseur en correspondance.

Différentes formes de curseur sont utilisées pour informer l'utilisateur de l'action que va avoir la souris. Par exemple, quand vous modifiez ou sélectionnez du texte, un curseur Cursors.IBeam est généralement affiché. Un curseur d'attente est couramment utilisé pour informer l'utilisateur qu'un processus est en cours d'exécution. Les processus nécessitant l'attente de l'utilisateur peuvent être, par exemple, l'ouverture d'un fichier, l'enregistrement d'un fichier ou le remplissage avec une grande quantité de données d'un contrôle, tel que DataGrid, ListBox ou TreeView.

Tous les contrôles qui dérivent de la classe Control ont une propriété Cursor. Pour modifier le curseur affiché par le pointeur de souris quand il est dans les limites du contrôle, assignez un Cursor à la propriété Cursor du contrôle. Vous pouvez également afficher des curseurs au niveau de l'application en assignant un Cursor à la propriété Current. Par exemple, si la fonction de votre application consiste à éditer un fichier texte, vous pouvez alors affecter Cursors.WaitCursor à la propriété Current pour afficher un curseur d'attente sur l'application pendant que le fichier procède à un chargement ou à un enregistrement, afin d'éviter le traitement de tout événement de souris. Une fois le processus terminé, affectez Cursors.Default à la propriété Current pour que l'application affiche le curseur approprié sur chaque type de contrôle.

RemarqueRemarque

Si vous appelez Application.DoEvents avant de réaffecter le curseur Cursors.Default à la propriété Current, l'application reprend alors l'écoute des événements de souris et l'affichage du Cursor approprié pour chaque contrôle dans l'application.

Des objets curseur peuvent être créés à partir de différentes sources, telles que le handle d'un Cursor existant, un fichier Cursor standard, une ressource, ou un flux de données.

RemarqueRemarque

La classe Cursor ne prend pas en charge les curseurs animés (fichiers .ani), ni les curseurs dotés de couleurs autres que le noir et le blanc.

Si l'image que vous utilisez comme curseur est trop petite, vous pouvez utiliser la méthode DrawStretched pour ajuster l'image aux limites du curseur. Vous pouvez masquer temporairement le curseur en appelant la méthode Hide et la restaurer en appelant la méthode Show.

ExempleExemple

L'exemple de code suivant affiche un formulaire qui illustre l'utilisation d'un curseur personnalisé. Le Cursor personnalisé est incorporé dans le fichier de ressources de l'application. Cet exemple nécessite un curseur contenu dans un fichier curseur nommé MyCursor.cur. Pour compiler cet exemple à l'aide de la ligne de commande, ajoutez l'indicateur suivant : /res:MyCursor.Cur, CustomCursor.MyCursor.Cur



Visual Basic
Imports System
Imports System.Drawing
Imports System.Windows.Forms

Namespace CustomCursor
   
   Public Class Form1
      Inherits System.Windows.Forms.Form
      
      <System.STAThread()> _
      Public Shared Sub Main()
         System.Windows.Forms.Application.Run(New Form1())
      End Sub 'Main

      Public Sub New()

         Me.ClientSize = New System.Drawing.Size(292, 266)
         Me.Text = "Cursor Example"
         
         ' Looks namespace.MyCursor.cur in the assemblies manifest.
         
         ' The following generates a cursor from an embedded resource.
         ' To add a custom cursor, create or use an existing 16x16 bitmap
         '        1. Add a new cursor file to your project: 
         '                File->Add New Item->Local Project Items->Cursor File
         '        2. Select 16x16 image type:
         '                Image->Current Icon Image Types->16x16
         ' --- To make the custom cursor an embedded resource  ---
         ' In Visual Studio:
         '        1. Select the cursor file in the Solution Explorer
         '        2. Choose View->Properties.
         '        3. In the properties window switch "Build Action" to "Embedded"
         ' On the command line:
         '        Add the following flag:
         '            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
         '
         ' The following line uses the namespace from the passed-in type
         ' and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
     ' NOTE: The cursor name is acase sensitive.        
     
         Me.Cursor = New Cursor(Me.GetType(), "MyCursor.Cur") 
      End Sub 'New       
   End Class 'Form1
End Namespace 'CustomCursor


C#
using System;
using System.Drawing;
using System.Windows.Forms;

namespace CustomCursor
{
    public class Form1 : System.Windows.Forms.Form
    {
        [STAThread]
        static void Main() 
        {
            Application.Run(new Form1());
        }

        public Form1()
        {
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Text = "Cursor Example";
            
            // The following generates a cursor from an embedded resource.
            
            // To add a custom cursor, create or use an existing 16x16 bitmap
            //        1. Add a new cursor file to your project: 
            //                File->Add New Item->Local Project Items->Cursor File
            //        2. Select 16x16 image type:
            //                Image->Current Icon Image Types->16x16

            // --- To make the custom cursor an embedded resource  ---
            
            // In Visual Studio:
            //        1. Select the cursor file in the Solution Explorer
            //        2. Choose View->Properties.
            //        3. In the properties window switch "Build Action" to "Embedded"

            // On the command line:
            //        Add the following flag:
            //            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
            //        
            //        Where "Namespace" is the namespace in which you want to use the cursor
            //        and   "CursorFileName.Cur" is the cursor filename.

            // The following line uses the namespace from the passed-in type
            // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
        // NOTE: The cursor name is acase sensitive.
            this.Cursor = new Cursor(GetType(), "MyCursor.Cur");  
           
        }
    }
}


C++
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

namespace CustomCursor
{
   public ref class Form1: public System::Windows::Forms::Form
   {
   public:
      Form1()
      {
         this->ClientSize = System::Drawing::Size( 292, 266 );
         this->Text = "Cursor Example";
         
         // The following generates a cursor from an embedded resource.
         // To add a custom cursor, create or use an existing 16x16 bitmap
         //        1. Add a new cursor file to your project:
         //                File->Add New Item->Local Project Items->Cursor File
         //        2. Select 16x16 image type:
         //                Image->Current Icon Image Types->16x16
         // --- To make the custom cursor an embedded resource  ---
         // In Visual Studio:
         //        1. Select the cursor file in the Solution Explorer
         //        2. Choose View->Properties.
         //        3. In the properties window switch "Build Action" to "Embedded"
         // On the command line:
         //        Add the following flag:
         //            /res:CursorFileName.Cur, Namespace.CursorFileName.Cur
         //
         //        Where "Namespace" is the namespace in which you want to use the cursor
         //        and   "CursorFileName.Cur" is the cursor filename.
         // The following line uses the namespace from the passed-in type
         // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
         // NOTE: The cursor name is case sensitive.
         this->Cursor = gcnew System::Windows::Forms::Cursor( GetType(),"MyCursor.Cur" );
      }

   };

}


[STAThread]
int main()
{
   Application::Run( gcnew CustomCursor::Form1 );
}



J#
package CustomCursor;

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;

public class Form1 extends System.Windows.Forms.Form
{
    /** @attribute STAThread()
     */
    public static void main(String[] args)
    {
        Application.Run(new Form1());
    } //main

    public Form1()
    {
        this.set_ClientSize(new System.Drawing.Size(292, 266));
        this.set_Text("Cursor Example");
        // The following generates a cursor from an embedded resource.
        // To add a custom cursor, create or use an existing 16x16 bitmap
        //        1. Add a new cursor file to your project: 
        //                File->Add New Item->Local Project Items->Cursor File
        //        2. Select 16x16 image type:
        //                Image->Current Icon Image Types->16x16
        // --- To make the custom cursor an embedded resource  ---
        // In Visual Studio:
        //        1. Select the cursor file in the Solution Explorer
        //        2. Choose View->Properties.
        //        3. In the properties window switch "Build Action" to "Embedded"
        // On the command line:
        //        Add the following flag:
        //            /res:CursorFileName.Cur,Namespace.CursorFileName.Cur
        //        
        //        Where "Namespace" is the namespace in which you want to use
        //        the cursor and   "CursorFileName.Cur" is the cursor filename.
        // The following line uses the namespace from the passed-in type
        // and looks for CustomCursor.MyCursor.Cur in the assemblies manifest.
        // NOTE: The cursor name is acase sensitive.
        this.set_Cursor(new Cursor(GetType(), "MyCursor.Cur"));
    } //Form1 
} //Form1

L'exemple de code suivant affiche les informations client dans un contrôle TreeView. Les n?uds d'arbre racine affichent les noms des clients, tandis que les n?uds d'arbre enfants affichent les numéros de commande assignés à chaque client. Dans cet exemple, 1000 clients sont affichés avec 15 commandes chacun. Les méthodes BeginUpdate et EndUpdate permettent d'éviter que TreeView ne soit repeint et un Cursor d'attente est affiché pendant que TreeView crée et peint les objets TreeNode. Cet exemple suppose que vous disposez d'un fichier curseur nommé MyWait.cur dans le répertoire de l'application. Il nécessite également un objet Customer, qui peut contenir une collection d'objets Order, et la création d'une instance d'un contrôle TreeView sur un Form.



Visual Basic
' Create a new ArrayList to hold the Customer objects.
Private customerArray As New ArrayList()

Private Sub FillMyTreeView()
   ' Add customers to the ArrayList of Customer objects.
   Dim x As Integer
   For x = 0 To 999
      customerArray.Add(New Customer("Customer" + x.ToString()))
   Next x

   ' Add orders to each Customer object in the ArrayList.
   Dim customer1 As Customer
   For Each customer1 In customerArray
      Dim y As Integer
      For y = 0 To 14
         customer1.CustomerOrders.Add(New Order("Order" + y.ToString()))
      Next y
   Next customer1

   ' Display a wait cursor while the TreeNodes are being created.
   Cursor.Current = New Cursor("MyWait.cur")

   ' Suppress repainting the TreeView until all the objects have been created.
   treeView1.BeginUpdate()

   ' Clear the TreeView each time the method is called.
   treeView1.Nodes.Clear()

   ' Add a root TreeNode for each Customer object in the ArrayList.
   Dim customer2 As Customer
   For Each customer2 In customerArray
      treeView1.Nodes.Add(New TreeNode(customer2.CustomerName))

      ' Add a child TreeNode for each Order object in the current Customer object.
      Dim order1 As Order
      For Each order1 In customer2.CustomerOrders
         treeView1.Nodes(customerArray.IndexOf(customer2)).Nodes.Add( _
    New TreeNode(customer2.CustomerName + "." + order1.OrderID))
      Next order1
   Next customer2

   ' Reset the cursor to the default for all controls.
   Cursor.Current = System.Windows.Forms.Cursors.Default

   ' Begin repainting the TreeView.
   treeView1.EndUpdate()
End Sub 'FillMyTreeView


C#
// Create a new ArrayList to hold the Customer objects.
private ArrayList customerArray = new ArrayList(); 

private void FillMyTreeView()
{
   // Add customers to the ArrayList of Customer objects.
   for(int x=0; x<1000; x++)
   {
      customerArray.Add(new Customer("Customer" + x.ToString()));
   }

   // Add orders to each Customer object in the ArrayList.
   foreach(Customer customer1 in customerArray)
   {
      for(int y=0; y<15; y++)
      {
         customer1.CustomerOrders.Add(new Order("Order" + y.ToString()));    
      }
   }

   // Display a wait cursor while the TreeNodes are being created.
   Cursor.Current = new Cursor("MyWait.cur");
        
   // Suppress repainting the TreeView until all the objects have been created.
   treeView1.BeginUpdate();

   // Clear the TreeView each time the method is called.
   treeView1.Nodes.Clear();

   // Add a root TreeNode for each Customer object in the ArrayList.
   foreach(Customer customer2 in customerArray)
   {
      treeView1.Nodes.Add(new TreeNode(customer2.CustomerName));
          
      // Add a child treenode for each Order object in the current Customer object.
      foreach(Order order1 in customer2.CustomerOrders)
      {
         treeView1.Nodes[customerArray.IndexOf(customer2)].Nodes.Add(
           new TreeNode(customer2.CustomerName + "." + order1.OrderID));
      }
   }

   // Reset the cursor to the default for all controls.
   Cursor.Current = Cursors.Default;

   // Begin repainting the TreeView.
   treeView1.EndUpdate();
}


C++
void FillMyTreeView()
{
   // Add customers to the ArrayList of Customer objects.
   for ( int x = 0; x < 1000; x++ )
   {
      customerArray->Add( gcnew Customer( "Customer " + x ) );
   }
   
   // Add orders to each Customer object in the ArrayList.
   IEnumerator^ myEnum = customerArray->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Customer^ customer1 = safe_cast<Customer^>(myEnum->Current);
      for ( int y = 0; y < 15; y++ )
      {
         customer1->CustomerOrders->Add( gcnew Order( "Order " + y ) );
      }
   }

   // Display a wait cursor while the TreeNodes are being created.
   ::Cursor::Current = gcnew System::Windows::Forms::Cursor( "MyWait.cur" );
   
   // Suppress repainting the TreeView until all the objects have been created.
   treeView1->BeginUpdate();
   
   // Clear the TreeView each time the method is called.
   treeView1->Nodes->Clear();
   
   // Add a root TreeNode for each Customer object in the ArrayList.
   while ( myEnum->MoveNext() )
   {
      Customer^ customer2 = safe_cast<Customer^>(myEnum->Current);
      treeView1->Nodes->Add( gcnew TreeNode( customer2->CustomerName ) );
      
      // Add a child treenode for each Order object in the current Customer object.
      IEnumerator^ myEnum = customer2->CustomerOrders->GetEnumerator();
      while ( myEnum->MoveNext() )
      {
         Order^ order1 = safe_cast<Order^>(myEnum->Current);
         treeView1->Nodes[ customerArray->IndexOf( customer2 ) ]->Nodes->Add( gcnew TreeNode( customer2->CustomerName + "." + order1->OrderID ) );
      }
   }
   
   // Reset the cursor to the default for all controls.
   ::Cursor::Current = Cursors::Default;
   
   // Begin repainting the TreeView.
   treeView1->EndUpdate();
}


J#
// Create a new ArrayList to hold the Customer objects.
private ArrayList customerArray = new ArrayList();

private void FillMyTreeView()
{
    // Add customers to the ArrayList of Customer objects.
    for (int x = 0; x < 1000; x++) {
        customerArray.Add(new Customer("Customer"
            + ((Int32)x).ToString()));
    }
    // Add orders to each Customer object in the ArrayList.
    for (int iCtr = 0; iCtr < customerArray.get_Count(); iCtr++) {
        Customer customer1 = (Customer)customerArray.get_Item(iCtr);
        for (int y = 0; y < 15; y++) {
            customer1.get_CustomerOrders().Add(new Order("Order"
                + ((Int32)y).ToString()));
        }
    }
    // Display a wait cursor while the TreeNodes are being created.
    get_Cursor().set_Current(new Cursor("MyWait.cur"));
    // Suppress repainting the TreeView until all the objects have
    // been created.
    treeView1.BeginUpdate();
    // Clear the TreeView each time the method is called.
    treeView1.get_Nodes().Clear();
    // Add a root TreeNode for each Customer object in the ArrayList.
    for (int iCtr1 = 0; iCtr1 < customerArray.get_Count(); iCtr1++) {
        Customer customer2 = (Customer)customerArray.get_Item(iCtr1);
        treeView1.get_Nodes().Add(new TreeNode(customer2.get_CustomerName()));
        // Add a child treenode for each Order object in the current
        // Customer object.
        for (int iCtr2 = 0; iCtr2 < customer2.get_CustomerOrders().
            get_Count(); iCtr2++) {
            Order order1 = (Order)customer2.get_CustomerOrders().
                get_Item(iCtr2);
            treeView1.get_Nodes().
                get_Item(customerArray.IndexOf(customer2)).get_Nodes().
                Add(new TreeNode(customer2.get_CustomerName() + "."
                + order1.get_OrderID()));
        }
    }
    // Reset the cursor to the default for all controls.
    get_Cursor().set_Current(Cursors.get_Default());
    // Begin repainting the TreeView.
    treeView1.EndUpdate();
} //FillMyTreeView
Hiérarchie d'héritageHiérarchie d'héritage
System.Object
  System.Windows.Forms.Cursor
Sécurité des threadsSécurité des threads
Les membres statiques publics (Shared en Visual Basic) de ce type sont thread-safe. Il n'est pas garanti que les membres d'instance soient thread-safe.
Plates-formesPlates-formes

Windows 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 versionInformations de version

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

.NET Compact Framework

Prise en charge dans : 2.0, 1.0
Voir aussiVoir aussi

Ces informations proviennent du site de http://msdn2.microsoft.com
Source de cette page : http://msdn2.microsoft.com/fr-fr/library/system.windows.forms.cursor.aspx

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

9 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-6346
Document créé le 30/10/06 03:07, dernière modification le Vendredi 17 Juin 2011, 12:11
Source du document imprimé : http://www.gaudry.be/dotnet-rf-system.windows.forms.cursor.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,49 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Pour te donner tous les conseils que je te prodiguais, il a fallu aussi que je me trompe, et cela m'est arrivé souvent.

Marc Levy [Extrait de Et si c'était vrai...]
 
l'infobrol
Nous sommes le Vendredi 01 Juin 2012, 04:58, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)