Register for your free account! | Forgot your password?

You last visited: Today at 03:26

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



System.Drawing

Discussion on System.Drawing within the CO2 Programming forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
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.
xScott is offline  
Old 07/04/2010, 21:03   #2
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Quote:
Originally Posted by xScott View Post
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.
Try doing this.

Code:
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Graphics GE = Graphics.FromHwnd(this.Handle);
            Pen PE = new Pen(Color.Black);
[B]            int X = 10;
            int Y = 10;[/B]
            Rectangle NE = new Rectangle(15, 15, [B]X, Y[/B]);

            if (e.KeyCode == Keys.Down)
            {
                Y++;
                GE.DrawRectangle(PE, NE);
            }
        }
Ian* is offline  
Old 07/05/2010, 01:26   #3
 
xScott's Avatar
 
elite*gold: 0
Join Date: Nov 2009
Posts: 322
Received Thanks: 63
Quote:
Originally Posted by Ian* View Post
Try doing this.

Code:
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            Graphics GE = Graphics.FromHwnd(this.Handle);
            Pen PE = new Pen(Color.Black);
[B]            int X = 10;
            int Y = 10;[/B]
            Rectangle NE = new Rectangle(15, 15, [B]X, Y[/B]);

            if (e.KeyCode == Keys.Down)
            {
                Y++;
                GE.DrawRectangle(PE, NE);
            }
        }
didn't work ><
xScott is offline  
Old 07/05/2010, 02:42   #4
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Do you have a Form1_Paint event?

Try putting that code in there and use key presses to draw.

haven't used System.Drawing for anything besides dmaps :P
Ian* is offline  
Thanks
1 User
Old 07/06/2010, 04:06   #5
 
I.P's Avatar
 
elite*gold: 0
Join Date: Dec 2009
Posts: 15
Received Thanks: 5
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.

edit: Surprised Ian did not know this :P
I.P is offline  
Thanks
1 User
Old 07/06/2010, 11:03   #6
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Quote:
Originally Posted by I.P View Post
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.

edit: Surprised Ian did not know this :P
His problem is making it draw while he hold the key down :P

Don't think you have to clear anything, he'd just be drawing a rectangle that eventually becomes solid since it fills up so fast
Ian* is offline  
Thanks
1 User
Old 07/06/2010, 11:53   #7
 
I.P's Avatar
 
elite*gold: 0
Join Date: Dec 2009
Posts: 15
Received Thanks: 5
No but he will have to store his variables in an array and call them every time he needs them if you get what I mean
I.P is offline  
Thanks
1 User
Old 07/06/2010, 12:12   #8
 
Ian*'s Avatar
 
elite*gold: 0
Join Date: Nov 2006
Posts: 805
Received Thanks: 464
Ah I see, I've only used Drawing for loading dmaps

So never had to do it that way lol.

Speaking of which i need to add those to my new bot >.>
Ian* is offline  
Thanks
1 User
Old 07/06/2010, 12:14   #9
 
I.P's Avatar
 
elite*gold: 0
Join Date: Dec 2009
Posts: 15
Received Thanks: 5
Fun dun ^.^

better than watching video tutorials trust me ;D
I.P is offline  
Thanks
1 User
Old 07/08/2010, 02:19   #10
 
elite*gold: 0
Join Date: Oct 2009
Posts: 128
Received Thanks: 50
What does this have to do with CO2?

The problem with your code and Ian*'s is that you're both redeclaring and reinstantiating the variables that depend on the Rectangle's location. You may alter those values at the bottom of that method, but you're losing those changes because either your Rectangle variable or your X and Y variables need to be declared at the class level.

It may be more preferable to use the and instead of using the UI's event dispatch thread. may provide you with some useful examples.
s.bat is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
Action 6 is drawing near ^^
03/17/2010 - Dekaron - 9 Replies
::: Welcome to GAMEHI ::: And here i thought it was going to be at the end of march XD Woot lets go own with our new skills and bust up some new maps ^^
SRO related drawing
01/19/2008 - Silkroad Online - 6 Replies
I am making a drawing of a Glaiver, I was just bored and wanted to get peoples opinion, it does not use any of the sro armor, I made up my own items, the glaive is somewhat like the level 100 glaive. http://img147.imageshack.us/img147/4301/scannedim agedl3.th.jpg Leave a comment. :) It is still a drawing in progress, not done yet. Quality is really low in imageshack, I do not know any other place. Download attachment, maybe it has better details...



All times are GMT +2. The time now is 03:26.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.