Skip to content

Instantly share code, notes, and snippets.

@harujoh
Created October 3, 2019 02:55
Show Gist options
  • Save harujoh/a456719cb639c650ca9fd2cbe32ca0e6 to your computer and use it in GitHub Desktop.
Save harujoh/a456719cb639c650ca9fd2cbe32ca0e6 to your computer and use it in GitHub Desktop.
ペイント超簡易版
using System.Drawing;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
Point posPrevious;
public Form1()
{
InitializeComponent();
Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
using (Graphics g = Graphics.FromImage(bmp))
{
g.Clear(Color.White);
}
pictureBox1.BackgroundImage = bmp;
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
{
using (var front = pictureBox1.CreateGraphics())
{
if (e.Button == MouseButtons.Left)
{
front.DrawLine(Pens.Black, posPrevious, e.Location);
}
else if (e.Button == MouseButtons.Right)
{
front.FillEllipse(Brushes.White, posPrevious.X - 5, posPrevious.Y - 5, 10, 10);
front.FillEllipse(Brushes.White, e.Location.X - 5, e.Location.Y - 5, 10, 10);
front.DrawLine(new Pen(Color.White, 10), posPrevious, e.Location);
}
}
posPrevious = e.Location;
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
posPrevious = e.Location;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment