hi guys, iv just started to create a grid for my "game of life",
basically what i want to do is on mouse down i want the corresponding
cell to fill with the color selected for my brush. i have drawn the
grid as follows:
{
Pen p = new Pen(Color.Black);
g1 = Graphics.FromImage(grid);
for (int i = 0; i < 300; i = i + 50) ;
for (int i = 10; i < 300; i = i + 20)
{
g1.DrawLine(p, 10, i, 290, i);
}
for (int x = 10; x < 300; x = x + 20)
{
g1.DrawLine(p, x, 10, x, 290);
}
}
can anyone help me on how to fill the rectangles with my chosen color
when clicked on? do i need to use DrawRectangle instead of DrawLine for
the basic grid?
any help is great, thanks!!
Loading
Ryan AlfordPosted Dec 3, 2007, 4:05 PM
SimonPosted Dec 3, 2007, 3:23 PM
Ryan AlfordPosted Dec 3, 2007, 3:20 PM
SimonPosted Dec 3, 2007, 8:34 AM
ok, so now i have the rectangle drawing when the mouse is clicked, brilliant, it draws and fills the grid if i am precise in where i click. is there a way of filling a cell when i click that certain cell?? so far all i have to draw at the moment is:
private void Form4_MouseDown(object sender, MouseEventArgs e){
{
/*x = 31;
y = 31;
x2 = 91;
y2 = 91;
*/
SolidBrush myBrush = new SolidBrush(Color.Red); Graphics g = this.CreateGraphics(); //g.FillRectangle(myBrush, x, y, 19, 19);g.FillRectangle(myBrush, e.X, e.Y, 19, 19);
}
help! please! :)
SimonPosted Dec 2, 2007, 12:24 PM
again any help is brilliant, thnks
Ryan AlfordPosted Dec 1, 2007, 2:17 PM
to color just one solid color, yes, you can use a solid brush.
something like this...
SimonPosted Nov 30, 2007, 3:10 PM
Ryan AlfordPosted Nov 30, 2007, 1:35 PM
then use the the FillRectangle method of the Graphics object