Graphics.DrawIcon 方法
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在指定的座標上繪製指定的 Icon 所代表的影像。
DrawIcon(Icon, Rectangle) | |
DrawIcon(Icon, Int32, Int32) |
在指定的座標上繪製指定的 Icon 所代表的影像。 |
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
public:
void DrawIcon(System::Drawing::Icon ^ icon, System::Drawing::Rectangle targetRect);
C#
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
null
。
範例
下列程式代碼範例是專為搭配 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 );
}
C#
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
適用於
.NET 9 和其他版本
產品 | 版本 |
---|---|
.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 |
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
- 來源:
- Graphics.cs
在指定的座標上繪製指定的 Icon 所代表的影像。
public:
void DrawIcon(System::Drawing::Icon ^ icon, int x, int y);
C#
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)
參數
- x
- Int32
繪製影像左上角的 X 座標。
- y
- Int32
繪製影像左上角的 Y 座標。
例外狀況
icon
null
。
範例
下列程式代碼範例是專為搭配 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 );
}
C#
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
適用於
.NET 9 和其他版本
產品 | 版本 |
---|---|
.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 |