LoginSignup
1
0

More than 1 year has passed since last update.

cscの作法 その272

Last updated at Posted at 2022-09-17

概要

cscの作法、調べてみた。
.NETFramework2.0 に書き直してみた。

写真

image.png

参考にしたページ

サンプルコード

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());
		}
	}
}





以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0