Click here to Skip to main content
15,920,217 members
Home / Discussions / C#
   

C#

 
QuestionCasting EventHandlers problem Pin
hdv21216-Aug-08 12:01
hdv21216-Aug-08 12:01 
AnswerRe: Casting EventHandlers problem Pin
lisan_al_ghaib16-Aug-08 13:15
lisan_al_ghaib16-Aug-08 13:15 
GeneralRe: Casting EventHandlers problem Pin
hdv21216-Aug-08 23:33
hdv21216-Aug-08 23:33 
AnswerRe: Casting EventHandlers problem Pin
lisan_al_ghaib17-Aug-08 0:16
lisan_al_ghaib17-Aug-08 0:16 
GeneralRe: Casting EventHandlers problem Pin
hdv21217-Aug-08 0:25
hdv21217-Aug-08 0:25 
GeneralRe: Casting EventHandlers problem Pin
N a v a n e e t h17-Aug-08 4:30
N a v a n e e t h17-Aug-08 4:30 
GeneralRe: Casting EventHandlers problem Pin
hdv21217-Aug-08 9:28
hdv21217-Aug-08 9:28 
QuestionProblems with Keyboard input (KeyDown, KeyPress, KeyUp) Pin
poppabaggins16-Aug-08 9:54
poppabaggins16-Aug-08 9:54 
Hi,

I'm a rather new C# user and I'm still figuring out the ropes of forms programming and such.
For the part of the program I'm working on, I basically want to move an image around on the screen, in a region (advanced, I know <end sarcasm="">). I achieved this just fine with mouse click and drag, but I'm unable to get any sort of keyboard input. Here's the part of the code I'm using:

protected override void OnPaint(PaintEventArgs e)
{
    Graphics g = e.Graphics;

    using(Region boardRegion = new Region(new Rectangle(ClientRectangle.X, ClientRectangle.Y,
        (int)(ClientRectangle.Width), (int)(ClientRectangle.Height * boardRegionSize))))
    {
        g.Clip = boardRegion;
        using(Bitmap boardImage = new Bitmap(board.ImagePath)){
            g.DrawImage(boardImage, board.X, board.Y);
        }
    }
    base.OnPaint(e);
}

private void CMGame_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Up)
        board.Y -= 30;
}


And for part of InitializeComponent(), I have
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.CMGame_KeyDown);


(automatically done by windows)

Basically, nothing happens when I press a key (the up arrow or anything else, since I've tried different keys in testing)

I read somewhere that I could try overriding WndProc, but I don't know how I would do this (even after I wrote the override method header and and found the code for KeyDown, 0x0100)

For reference, I also have a button in the form with a click event.

Help would be much appreciated.
AnswerRe: Problems with Keyboard input (KeyDown, KeyPress, KeyUp) Pin
DaveyM6916-Aug-08 10:14
professionalDaveyM6916-Aug-08 10:14 
GeneralRe: Problems with Keyboard input (KeyDown, KeyPress, KeyUp) Pin
poppabaggins16-Aug-08 11:53
poppabaggins16-Aug-08 11:53 
GeneralRe: Problems with Keyboard input (KeyDown, KeyPress, KeyUp) [modified] Pin
poppabaggins17-Aug-08 11:27
poppabaggins17-Aug-08 11:27 
GeneralRe: Problems with Keyboard input (KeyDown, KeyPress, KeyUp) Pin
DaveyM6917-Aug-08 23:13
professionalDaveyM6917-Aug-08 23:13 
GeneralRe: Problems with Keyboard input (KeyDown, KeyPress, KeyUp) Pin
poppabaggins18-Aug-08 2:58
poppabaggins18-Aug-08 2:58 
QuestionGet started with keylistening, even when out of focus.. Pin
Joplinazz16-Aug-08 9:01
Joplinazz16-Aug-08 9:01 
AnswerRe: Get started with keylistening, even when out of focus.. Pin
DaveyM6916-Aug-08 10:08
professionalDaveyM6916-Aug-08 10:08 
GeneralRe: Get started with keylistening, even when out of focus.. Pin
Joplinazz16-Aug-08 13:00
Joplinazz16-Aug-08 13:00 
QuestionInterface inheritance problem. Pin
hdv21216-Aug-08 5:58
hdv21216-Aug-08 5:58 
AnswerRe: Interface inheritance problem. Pin
Wendelius16-Aug-08 6:10
mentorWendelius16-Aug-08 6:10 
AnswerRe: Interface inheritance problem. Pin
User 665816-Aug-08 6:16
User 665816-Aug-08 6:16 
AnswerRe: Interface inheritance problem. Pin
DaveyM6916-Aug-08 6:16
professionalDaveyM6916-Aug-08 6:16 
GeneralRe: Interface inheritance problem. Pin
User 665816-Aug-08 6:23
User 665816-Aug-08 6:23 
GeneralRe: Interface inheritance problem. Pin
DaveyM6916-Aug-08 6:32
professionalDaveyM6916-Aug-08 6:32 
AnswerRe: Interface inheritance problem. Pin
Roger Alsing18-Aug-08 2:54
Roger Alsing18-Aug-08 2:54 
QuestionC# TreeView Node Image Not Correct Pin
Kevin Marois16-Aug-08 5:12
professionalKevin Marois16-Aug-08 5:12 
AnswerRe: C# TreeView Node Image Not Correct Pin
Wendelius16-Aug-08 6:01
mentorWendelius16-Aug-08 6:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.