Graphics.DrawIconUnstretched(Icon, Rectangle) 方法

定義

繪製指定的 Icon 所代表的影像,而不調整影像。

public void DrawIconUnstretched (System.Drawing.Icon icon, System.Drawing.Rectangle targetRect);

參數

icon
Icon

要繪製的 Icon

targetRect
Rectangle

Rectangle 結構,指定所產生影像的位置和大小。 影像不會縮放以符合此矩形,但會保留其原始大小。 如果影像大於矩形,則會裁剪以符合其內部。

例外狀況

icon null

範例

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

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

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

  • 將圖示繪製至畫面。

矩形的位置會在畫面上找出圖示,而且繪製的圖示會取消縮放且未調整。

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);
}

適用於

產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9