I have this simple code each time i click the button its drawing a point in the pictureBox1 at location 100,100
But i want to calculate first ( i need to learn how to do it ) the center of the pictureBox1.
Then i want to use the Random so each time i click the button it will draw a point randomaly from the pictureBox1 center location + 10
private void button5_MouseClick(object sender, MouseEventArgs e)
{
Random rnd = new Random();
drawPoint(100, 100);
}
public void drawPoint(int x, int y)
{
Graphics g = Graphics.FromHwnd(pictureBox1.Handle);
SolidBrush brush = new SolidBrush(Color.LimeGreen);
Point dPoint = new Point(x, (pictureBox1.Height - y));
dPoint.X = dPoint.X - 2;
dPoint.Y = dPoint.Y - 2;
Rectangle rect = new Rectangle(dPoint, new Size(4, 4));
g.FillRectangle(brush, rect);
g.Dispose();
}
Try this. It will calculate random offset from the centre by +10 -10