System.Drawing

Posts 1–3 of 3 · Page 1 of 1
System.Drawing
Not strong in this :L
Not good with Forms, Events and system.Drawing
Im making a key event draw a new Rectangle when the key is (Down) is pressed, but its not drawing a new rectangle when i press down continuously:

Code:
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Graphics GE = Graphics.FromHwnd(this.Handle);
            Pen PE = new Pen(Color.Black);
            Rectangle NE = new Rectangle(15, 15, 20, 50);

            if (e.KeyCode == Keys.Down)
            {
                NE.Y++;
                GE.DrawRectangle(PE, NE);
            }
        }
Can you please point me in the right direction, even though i've probably got this completely wrong :L
Shouldn't this be drawing a new rectangle, but displaced in Y Direction by 1 everytime the Down key is pressed?

EDIT:
Tried doing:

Code:
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Graphics GE = Graphics.FromHwnd(this.Handle);
            Pen PE = new Pen(Color.Black);
            Rectangle NE = new Rectangle(15, 15, 20, 50);
            GE.DrawRectangle(PE, NE);

            if (e.KeyCode == Keys.Down)
            {

                  NE.OffSet(17,17);
            }
        }
To move the current shape drawn, but it doesn't move at all.
Graphics are cleared each frame, so if you want a new one + the older ones, you'll have to store them in an array and redraw them all each frame.
my problem is making it draw while I hold the key down :P

Don't think I have to clear anything, I'm just drawing a rectangle that eventually becomes solid since it fills up so fast
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?