Graphics.DrawIconとは? わかりやすく解説

Graphics.DrawIcon メソッド (Icon, Int32, Int32)

指定した Icon によって表されるイメージを指定した座標に描画します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawIcon ( _
    icon As Icon, _
    x As Integer, _
    y As Integer _
)
Dim instance As Graphics
Dim icon As Icon
Dim x As Integer
Dim y As Integer

instance.DrawIcon(icon, x, y)
public void DrawIcon (
    Icon icon,
    int x,
    int y
)
public:
void DrawIcon (
    Icon^ icon, 
    int x, 
    int y
)
public void DrawIcon (
    Icon icon, 
    int x, 
    int y
)
public function DrawIcon (
    icon : Icon, 
    x : int, 
    y : int
)

パラメータ

icon

描画する Icon。

x

描画イメージの左上隅の x 座標。

y

描画イメージの左上隅の y 座標。

例外例外
例外の種類条件

ArgumentNullException

icon が null 参照 (Visual Basic では Nothing) です。

使用例使用例

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。

描画したアイコンはスケーリングされていません。

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawIcon メソッド (Icon, Rectangle)

Rectangle 構造体で指定された領域内の指定した Icon によって表されるイメージを描画します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub DrawIcon ( _
    icon As Icon, _
    targetRect As Rectangle _
)
Dim instance As Graphics
Dim icon As Icon
Dim targetRect As Rectangle

instance.DrawIcon(icon, targetRect)
public void DrawIcon (
    Icon icon,
    Rectangle targetRect
)
public:
void DrawIcon (
    Icon^ icon, 
    Rectangle targetRect
)
public void DrawIcon (
    Icon icon, 
    Rectangle targetRect
)
public function DrawIcon (
    icon : Icon, 
    targetRect : Rectangle
)

パラメータ

icon

描画する Icon。

targetRect

ディスプレイ表面における生成イメージの場所とサイズを指定する Rectangle 構造体。icon パラメータに含まれるイメージは、この四角形領域の大きさに合わせてスケーリングされます。

例外例外
例外の種類条件

ArgumentNullException

icon が null 参照 (Visual Basic では Nothing) です。

使用例使用例

次の例は、Windows フォームでの使用を意図してデザインされており、Paint イベント ハンドラのパラメータである PaintEventArgse が必要です。このコードは次のアクションを実行します。

四角形の位置によって画面上のアイコンの場所が決まり、四角形のサイズによって描画したアイコンのスケーリングが決まります。

Public 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
public 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);
}
public:
   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 );
   }
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.DrawIcon メソッド




英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Graphics.DrawIcon」の関連用語

Graphics.DrawIconのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Graphics.DrawIconのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS