概要
cscの作法、調べてみた。
.NETFramework2.0 に書き直してみた。
写真
参考にしたページ
サンプルコード
using System;
using System.Drawing;
using System.Windows.Forms;
namespace App
{
public partial class form1 : Form {
Bitmap Bm;
bool mouseDrug;
int prevX;
int prevY;
PictureBox DrawingPicBox;
public form1() {
DrawingPicBox = new PictureBox();
DrawingPicBox.Size = new Size(300, 300);
DrawingPicBox.MouseDown += new MouseEventHandler(DrawingPicBox_MouseDown);
DrawingPicBox.MouseUp += new MouseEventHandler(DrawingPicBox_MouseUp);
DrawingPicBox.MouseMove += new MouseEventHandler(DrawingPicBox_MouseMove);
this.Controls.Add(DrawingPicBox);
Bm = new Bitmap(DrawingPicBox.Width, DrawingPicBox.Height);
}
private void DrawingPicBox_MouseDown(object sender, MouseEventArgs e) {
mouseDrug = true;
prevX = e.Location.X;
prevY = e.Location.Y;
}
private void DrawingPicBox_MouseUp(object sender, MouseEventArgs e) {
mouseDrug = false;
}
private void DrawingPicBox_MouseMove(object sender, MouseEventArgs e) {
if (mouseDrug == true)
{
Graphics objGrp = Graphics.FromImage(Bm);
Pen objPen = new Pen(Color.Blue, 3);
objGrp.DrawLine(objPen, prevX, prevY, e.Location.X, e.Location.Y);
prevX = e.Location.X;
prevY = e.Location.Y;
objPen.Dispose();
objGrp.Dispose();
DrawingPicBox.Image = Bm;
}
}
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.Run(new form1());
}
}
}
以上。