Graphics.DrawIcon 方法

定義

在指定的座標處,繪製由指定之 Icon 所表示的影像。

多載

DrawIcon(Icon, Rectangle)

Rectangle 結構指定的區域中,繪製由指定之 Icon 表示的影像。

DrawIcon(Icon, Int32, Int32)

在指定的座標處,繪製由指定之 Icon 所表示的影像。

DrawIcon(Icon, Rectangle)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

Rectangle 結構指定的區域中,繪製由指定之 Icon 表示的影像。

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)

參數

icon
Icon

要繪製的 Icon

targetRect
Rectangle

Rectangle 結構,指定在顯示介面上產生影像的位置和大小。 包含在 icon 參數中的影像會縮放到這個矩形區域的維度。

例外狀況

iconnull

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse,這是事件處理程序的參數Paint。 此程式碼會執行下列動作:

  • 從範例資料夾中的標準 Windows 圖示檔案SampIcon.ico建立圖示。

  • 建立要在其中繪製圖示的矩形。

  • 將圖示繪製到畫面。

矩形的位置會找出螢幕上的圖示,而矩形的大小會決定繪製圖示的縮放比例。

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

適用於

DrawIcon(Icon, Int32, Int32)

來源:
Graphics.cs
來源:
Graphics.cs
來源:
Graphics.cs

在指定的座標處,繪製由指定之 Icon 所表示的影像。

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)

參數

icon
Icon

要繪製的 Icon

x
Int32

繪製影像左上角的 X 座標。

y
Int32

所繪製影像左上角的 Y 座標。

例外狀況

iconnull

範例

下列程式代碼範例是設計來搭配 Windows Forms 使用,而且需要 PaintEventArgse,這是事件處理程序的參數Paint。 此程式碼會執行下列動作:

  • 從範例資料夾中的標準 Windows 圖示檔案SampIcon.ico建立圖示。

  • 建立要繪製圖示之左上角的座標。

  • 將圖示繪製到畫面。

繪製的圖示未調整。

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

適用於