Graphics.DrawIconUnstretched(Icon, Rectangle) Metoda

Definicja

Rysuje obraz reprezentowany przez określony Icon bez skalowania obrazu.

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)

Parametry

icon
Icon

Icon aby narysować.

targetRect
Rectangle

Rectangle struktura określająca lokalizację i rozmiar wynikowego obrazu. Obraz nie jest skalowany tak, aby pasował do tego prostokąta, ale zachowuje oryginalny rozmiar. Jeśli obraz jest większy niż prostokąt, zostanie obcięty, aby zmieścił się w nim.

Wyjątki

icon to null.

Przykłady

Poniższy przykład kodu jest przeznaczony do użycia z Windows Forms i wymaga PaintEventArgseparametru Paint programu obsługi zdarzeń. Kod wykonuje następujące akcje:

  • Tworzy ikonę na podstawie standardowego pliku ikony systemu Windows SampIcon.ico w przykładowym folderze.

  • Tworzy prostokąt, w którym ma być rysowanie ikony.

  • Rysuje ikonę na ekranie.

Położenie prostokąta lokalizuje ikonę na ekranie, a narysowana ikona jest nieskalowana i nieskończona.

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

Dotyczy