语言

Graphics.DrawIcon 方法

定义

绘制由指定坐标处指定的 Icon 图像。

重载

名称 说明
DrawIcon(Icon, Rectangle)

绘制由结构指定的区域内指定的IconRectangle图像。

DrawIcon(Icon, Int32, Int32)

绘制由指定坐标处指定的 Icon 图像。

DrawIcon(Icon, Rectangle)

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

绘制由结构指定的区域内指定的IconRectangle图像。

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 图像缩放到此矩形区域的尺寸。

例外

icon 是 null。

示例

下面的代码示例设计用于 Windows 窗体,它需要 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)

Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
Graphics.cs
Source:
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 坐标。

例外

icon 是 null。

示例

下面的代码示例设计用于 Windows 窗体,它需要 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

适用于