Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Bitmap cursor;
- Graphics gCursor;
- Bitmap canvas;
- Graphics gPaint;
- bool isPainting = false;
- public MainForm()
- {
- InitializeComponent();
- this.DoubleBuffered = true;
- this.MouseMove += new MouseEventHandler(mouseMove);
- this.MouseDown += new MouseEventHandler(mouseDown);
- this.MouseUp += new MouseEventHandler(mouseUp);
- canvas = new Bitmap(this.Width, this.Height);
- gPaint = Graphics.FromImage(canvas);
- cursor = new Bitmap(this.Width, this.Height);
- gCursor = Graphics.FromImage(cursor);
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- gCursor.Clear(Color.Transparent);
- Point p = PointToClient(Cursor.Position);
- if (isPainting)
- {
- gPaint.FillRectangle(Brushes.Black, new Rectangle(p.X - 20, p.Y - 20, 40, 40));
- }
- gCursor.FillRectangle(Brushes.Black, new Rectangle(p.X - 20, p.Y - 20, 40, 40));
- gCursor.DrawRectangle(Pens.Red, new Rectangle(p.X - 20, p.Y - 20, 39, 39));
- e.Graphics.DrawImage(canvas, Point.Empty);
- e.Graphics.DrawImage(cursor, Point.Empty);
- }
- private void mouseMove(object sender, MouseEventArgs e)
- {
- this.Invalidate();
- }
- private void mouseDown(object sender, MouseEventArgs e)
- {
- isPainting = true;
- }
- private void mouseUp(object sender, MouseEventArgs e)
- {
- isPainting = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement