Graphics.DrawIconUnstretched(Icon, Rectangle) 方法

定义

在不缩放图像的情况下绘制由指定 Icon 表示的图像。

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)

参数

icon
Icon

要绘制的 Icon

targetRect
Rectangle

Rectangle 结构,用于指定生成的图像的位置和大小。 图像未缩放以适应此矩形,但保留其原始大小。 如果图像大于矩形,则会将其剪裁以容纳在矩形中。

例外

icon null

示例

下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:

  • 从示例文件夹中的标准 Windows 图标文件创建图标SampIcon.ico。

  • 创建一个要在其中绘制图标的矩形。

  • 将图标绘制到屏幕。

矩形的位置将定位屏幕上的图标,并且绘制的图标未缩放且未调整。

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

适用于