[2005] Creating a Class.cs File for Input & Otherstuff
Hi, I'm pretty new to C#, I've made a simple Duck Hunt game, but now I'm trying to creating a new game, called Jail Break. But anyways, what I would like to do is have all my PlayerInput (Keyboard Input) in one Class File instead of the Big Form1.cs Code File being gaint.
I've tried something like this.
Created new Class File called it PlayerInput.cs
In it, I have:
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace Jail_Break
{
class PlayerInput
{
}
}
Just a simple Class File, right? now I want in it is what shows up when you do a Event for Keydown in Form1.cs
Code:
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
}
So what I'm trying to do is have the Form1.cs KeyDown WHOLE CODE in the PlayerInput.cs File
Something like this:
Code:
using System;
using System.Collections.Generic;
using System.Text;
namespace Jail_Break
{
class PlayerInput
{
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
Code for KeyDown Here.. .. . . .
}
}
}
and then I would like to call the code either in the:
Code:
public Form1()
{
InitializeComponent();
Call Code Here . . . .
}
or in the Form1_Load Event.
Please someone help, this will make my code alot neater, and i can't figure out how to do something like this, I've never ever used a Created Class before for Events or Other stuff.
Thanks, Wesley
Re: [2005] Creating a Class.cs File for Input & Otherstuff
Well you won't be able to capture the event from the form in another class like that. What you may want to do is create a function in the class (you could call it OnKeyDown or anything). Then in the form, when the event triggers, just call the function you made within the class.