Graphics.DrawIconUnstretched(Icon, Rectangle) Metodo

Definizione

Disegna l'immagine rappresentata dall'oggetto Icon specificato senza adattamento.

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

Parametri

icon
Icon

Oggetto Icon da disegnare.

targetRect
Rectangle

Struttura Rectangle che specifica la posizione e le dimensioni dell'immagine risultante. L'immagine non viene adattata al rettangolo, ma conserva le sue dimensioni originali. Se è più larga del rettangolo, viene ritagliata per inserirla al suo interno.

Eccezioni

icon è null.

Esempio

L'esempio di codice seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice esegue le azioni seguenti:

  • Crea un'icona da un file di icone di Windows standard SampIcon.ico nella cartella di esempio.

  • Crea un rettangolo in cui disegnare l'icona.

  • Disegna l'icona sullo schermo.

La posizione del rettangolo individua l'icona sullo schermo e l'icona disegnata non viene ridimensionata e non ritagliata.

private:
   void DrawIconUnstretchedRectangle( 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->DrawIconUnstretched( newIcon, rect );
   }
private void DrawIconUnstretchedRectangle(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.DrawIconUnstretched(newIcon, rect);
}
Private Sub DrawIconUnstretchedRectangle(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.DrawIconUnstretched(newIcon, rect)
End Sub

Si applica a