/***********************************************************************/
/*★ PictureBox の画像の上から、PaintHandler で図形を描く 前田 稔 ★*/
/***********************************************************************/
using System;
using System.Drawing;
using System.Windows.Forms;
public class MyForm : Form
{
private PictureBox pictureBox1;
Image img = Image.FromFile(@"C:\Data\Test\Kishi.gif");
public MyForm()
{
// pictureBox1
pictureBox1 = new System.Windows.Forms.PictureBox();
pictureBox1.Location = new Point(12, 12);
pictureBox1.Size = new Size(258, 232);
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(PictureBox1_Paint);
pictureBox1.Image = img;
// MyForm
Controls.Add(pictureBox1);
}
private void PictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawRectangle(new Pen(Color.Red, 3f), new Rectangle(30, 20, 200, 30));
g.DrawEllipse(new Pen(Color.Blue), new Rectangle(50, 80, 160, 60));
}
}
class form01
{
public static void Main()
{
MyForm mf = new MyForm();
Application.Run(mf);
}
}
|