Graphics.DrawIconUnstretched(Icon, Rectangle) 方法

定义

绘制指定的 Icon 表示的图像,而不缩放该图像。Draws the image represented by the specified Icon without scaling the image.

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

要绘制的 IconIcon to draw.

targetRect
Rectangle

Rectangle 结构,它指定所绘制图像的位置和大小。Rectangle structure that specifies the location and size of the resulting image. 不缩放图像以适合此矩形的大小,但保留其原始大小。The image is not scaled to fit this rectangle, but retains its original size. 如果该图像比该矩形大,将它剪裁到适合它的大小。If the image is larger than the rectangle, it is clipped to fit inside it.

例外

iconnullicon is null.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:

  • 从示例文件夹中的标准 Windows 图标文件 SampIcon 创建一个图标。Creates an icon from a standard Windows icon file SampIcon.ico in the example folder.

  • 创建一个要在其中绘制图标的矩形。Creates a rectangle in which to draw the icon.

  • 将图标绘制到屏幕上。Draws the icon to the screen.

该矩形的位置将在屏幕上查找该图标,绘制的图标是无比例的且未剪辑。The position of the rectangle locates the icon on the screen, and the drawn icon is unscaled and unclipped.

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

适用于