Graphics.DrawIcon Méthode

Définition

Dessine l'image représentée par le Icon spécifié aux coordonnées indiquées.

Surcharges

DrawIcon(Icon, Rectangle)

Dessine l'image représentée par le Icon spécifié dans la zone indiquée par une structure Rectangle.

DrawIcon(Icon, Int32, Int32)

Dessine l'image représentée par le Icon spécifié aux coordonnées indiquées.

DrawIcon(Icon, Rectangle)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine l'image représentée par le Icon spécifié dans la zone indiquée par une structure Rectangle.

public:
 void DrawIcon(System::Drawing::Icon ^ icon, System::Drawing::Rectangle targetRect);
public void DrawIcon (System.Drawing.Icon icon, System.Drawing.Rectangle targetRect);
member this.DrawIcon : System.Drawing.Icon * System.Drawing.Rectangle -> unit
Public Sub DrawIcon (icon As Icon, targetRect As Rectangle)

Paramètres

icon
Icon

Icon à dessiner.

targetRect
Rectangle

Structure Rectangle qui spécifie l'emplacement et la taille de l'image résultante sur la surface d'affichage. L'image figurant dans le paramètre icon est ajustée aux dimensions de cette zone rectangulaire.

Exceptions

icon a la valeur null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :

  • Crée une icône à partir d’un fichier d’icônes Windows standard SampIcon.ico dans l’exemple de dossier.

  • Crée un rectangle dans lequel dessiner l’icône.

  • Dessine l’icône à l’écran.

La position du rectangle localise l’icône à l’écran, et la taille du rectangle détermine la mise à l’échelle de l’icône dessinée.

private:
   void DrawIconRectangle( PaintEventArgs^ e )
   {
      // Create icon.
      System::Drawing::Icon^ newIcon = gcnew System::Drawing::Icon( "SampIcon.ico" );

      // Create rectangle for icon.
      Rectangle rect = Rectangle(100,100,200,200);

      // Draw icon to screen.
      e->Graphics->DrawIcon( newIcon, rect );
   }
private void DrawIconRectangle(PaintEventArgs e)
{        
    // Create icon.
    Icon newIcon = new Icon("SampIcon.ico");
             
    // Create rectangle for icon.
    Rectangle rect = new Rectangle(100, 100, 200, 200);
             
    // Draw icon to screen.
    e.Graphics.DrawIcon(newIcon, rect);
}
Private Sub DrawIconRectangle(ByVal e As PaintEventArgs)

    ' Create icon.
    Dim newIcon As New Icon("SampIcon.ico")

    ' Create rectangle for icon.
    Dim rect As New Rectangle(100, 100, 200, 200)

    ' Draw icon to screen.
    e.Graphics.DrawIcon(newIcon, rect)
End Sub

S’applique à

DrawIcon(Icon, Int32, Int32)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs

Dessine l'image représentée par le Icon spécifié aux coordonnées indiquées.

public:
 void DrawIcon(System::Drawing::Icon ^ icon, int x, int y);
public void DrawIcon (System.Drawing.Icon icon, int x, int y);
member this.DrawIcon : System.Drawing.Icon * int * int -> unit
Public Sub DrawIcon (icon As Icon, x As Integer, y As Integer)

Paramètres

icon
Icon

Icon à dessiner.

x
Int32

Coordonnée x de l'angle supérieur gauche de l'image dessinée.

y
Int32

Coordonnée y de l'angle supérieur gauche de l'image dessinée.

Exceptions

icon a la valeur null.

Exemples

L’exemple de code suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code effectue les actions suivantes :

  • Crée une icône à partir d’un fichier d’icônes Windows standard SampIcon.ico dans l’exemple de dossier.

  • Crée les coordonnées du coin supérieur gauche au niveau duquel dessiner l’icône.

  • Dessine l’icône à l’écran.

L’icône dessinée n’est pas mise à l’échelle.

private:
   void DrawIconInt( PaintEventArgs^ e )
   {

      // Create icon.
      System::Drawing::Icon^ newIcon = gcnew System::Drawing::Icon( "SampIcon.ico" );

      // Create coordinates for upper-left corner of icon.
      int x = 100;
      int y = 100;

      // Draw icon to screen.
      e->Graphics->DrawIcon( newIcon, x, y );
   }
private void DrawIconInt(PaintEventArgs e)
{
    // Create icon.
    Icon newIcon = new Icon("SampIcon.ico");
             
    // Create coordinates for upper-left corner of icon.
    int x = 100;
    int y = 100;
             
    // Draw icon to screen.
    e.Graphics.DrawIcon(newIcon, x, y);
}
Private Sub DrawIconInt(ByVal e As PaintEventArgs)

    ' Create icon.
    Dim newIcon As New Icon("SampIcon.ico")

    ' Create coordinates for upper-left corner of icon.
    Dim x As Integer = 100
    Dim y As Integer = 100

    ' Draw icon to screen.
    e.Graphics.DrawIcon(newIcon, x, y)
End Sub

S’applique à