環境
Visual Studio 2015 (Win10標準の.net4.6がデフォルトで使えるため)
手順
1,新規プロジェクトを作る
2,フォームにPanelをドラッグする
3,プロパティのイベントからPaintのイベントハンドラをダブルクリックする
4,作成されたPaintベントハンドラpanel1_Paintにプログラムを記述する
private void panel1_Paint(object sender, PaintEventArgs e)
{
if (currentImage != null)
{
// 画像を0,0に描画する
e.Graphics.DrawImage(currentImage,
0, 0, currentImage.Width, currentImage.Height);
}
}
5,フォームクラスのメンバ変数にImageを登録する
public partial class Form1 : Form
{
//画像ファイルを読み込む
Image currentImage = Image.FromFile(@"C:\test\test.gif");
public Form1()
{
6,実行すると画像が表示できる