Chciałbym namalować koło w pictureBox1, lub też móc malować za pomocą klasy pen linie. Niestety mam błąd w moim kodzie w metodzie pictureBox1_Paint.
Error 1 'System.Drawing.Graphics' does not contain a definition for 'Graphics' and no extension method 'Graphics' accepting a first argument of type 'System.Drawing.Graphics' could be found (are you missing a using directive or an assembly reference?)
Proszę o pomoc w poprawieniu tego kodu.
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
private Graphics g;
Point mold, mcur;
public Form1()
{
InitializeComponent();
pictureBox1.Image = new Bitmap(300, 345);
g = Graphics.FromImage(pictureBox1.Image);
Pen pioro = new Pen(Color.Black);
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mold = e.Location;
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mcur = e.Location;
Invalidate();
}
}
private Rectangle rec(Point p1, Point p2)
{
Rectangle a = new Rectangle();
a.X = (p1.X > p2.X ? p2.X : p1.X);
a.Y = (p1.Y > p2.Y ? p2.Y : p1.Y);
a.Width = Math.Abs(p1.X - p2.Y);
a.Height = Math.Abs(p1.Y - p2.Y);
return a;
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
g.Graphics.DrawEllipse(Pens.Black, rec(mold, mcur));
}
}
}