Any help? Here’s my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Client
{
public partial class MainChat : Form
{
bool ShouldPaint = false;
public MainChat()
{
InitializeComponent();
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(400, 400);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);
this.MouseUp += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (ShouldPaint)
{
Graphics graphics = CreateGraphics();
graphics.FillEllipse(new SolidBrush(Color.Black), e.X, e.Y, 10, 10);
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
ShouldPaint = false;
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
ShouldPaint = true;
}
}
}
fix the line
to
The way you had it gets the graphics of the form like saying
this.CreateGraphics()that is why it draws on the form. All controls have aCreatGraphics()method for custom painting.