

private void Form1_Load(object sender, System.EventArgs e)
{
}
ここで初期化処理をすれば良さそうだ。
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
このあたりに追加。
public class Form1 : System.Windows.Forms.Form
{
// ユーザ定義変数
private System.Drawing.Bitmap bmp_Char = null;
こうしておいて、
private void Form1_Load(object sender, System.EventArgs e)
{
// キャラのBitmapインスタンスを生成
this.bmp_Char = new Bitmap("char.png");
}
これでファイルの読み込みはOKらしい。
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
PaintEventArgs e にGraphicsオブジェクトが含まれているので、指定したイメージを座標ペアで指定された位置に元の物理サイズで描画します。 [C#] public void DrawImageUnscaled( Image image, int x, int y ); パラメータ image 描画する Image オブジェクト。 x 描画イメージの左上隅の x 座標。 y 描画イメージの左上隅の y 座標。MSDNによるとこうらしい。
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(this.bmp_Char, 100, 200);
}
これでよし。
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace GDI_Prac
{
/// <summary>
/// Form1 の概要の説明です。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
// ユーザ定義変数
private System.Drawing.Bitmap bmp_Char = null;
private System.Windows.Forms.PictureBox pictureBox1;
/// <summary>
/// 必要なデザイナ変数です。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows フォーム デザイナ サポートに必要です。
//
InitializeComponent();
//
// TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
//
}
/// <summary>
/// 使用されているリソースに後処理を実行します。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows フォーム デザイナで生成されたコード
/// <summary>
/// デザイナ サポートに必要なメソッドです。このメソッドの内容を
/// コード エディタで変更しないでください。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.Color.White;
this.pictureBox1.Location = new System.Drawing.Point(0, 0);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(640, 480);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
this.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
this.ClientSize = new System.Drawing.Size(656, 493);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
// キャラのBitmapインスタンスを生成
this.bmp_Char = new Bitmap("char.png");
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.DrawImageUnscaled(this.bmp_Char, 100, 200);
}
}
}
Copyright (C) Zawa 2005
<<戻る>>