Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Bitmap bitmap;
- private Point oldPosition;
- private void Form1_Load(object sender, EventArgs e)
- {
- bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height);
- using (Graphics g = Graphics.FromImage(bitmap))
- g.Clear(Color.White);
- pictureBox1.Image = bitmap;
- }
- private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
- {
- oldPosition = e.Location;
- }
- * Determine whether the user actually wants to draw (is the left mouse button pressed?).
- * Draw the line into the bitmap.
- * Update the previous cursor position to the new position.
- * Display the results.
- private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
- {
- if (e.Button == System.Windows.Forms.MouseButtons.Left)
- {
- using (Graphics g = Graphics.FromImage(bitmap))
- g.DrawLine(Pens.Black, oldPosition, e.Location);
- oldPosition = e.Location;
- pictureBox1.Image = bitmap;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement