I'm trying to cast types in an application a friend asked me to look at for him, but my casts aren't working. I want to cast from EventArgs to KeyEventArgs. Is this possible?
Here's the just of it:
I'm getting an InvalidCastExce ption on line 9 (KeyEventArgs margs = (KeyEventArgs)e ;) which I understand but is there another way to cast EventArgs to KeyEventArgs? I'm not too sure about the inheritance of types this way...
Here's the just of it:
Code:
private void Form1_Load(object sender, EventArgs e)
{
MainMenu_Key(sender, e);
}
private void MainMenu_Key(object sender, EventArgs e)
{
KeyEventArgs margs = (KeyEventArgs)e;
lbl_result.Text = margs.KeyCode.ToString();
if (margs.KeyCode.ToString() == "D1")
{
if (tmrTIMER.Enabled == false && AvailableClicks != 0)
{
tmrTIMER.Enabled = true;
NextKeyToPress = 1;
}
KeyToPress = NextKeyToPress;
AvailableClicks -= Clickdeduction;
Actions += 1;
KeyPressed = 1;
#region ///colorchange\\\
if (KeyPressed == KeyToPress)
{ CorrectClick = 1; }
else { CorrectClick = 0; }
#endregion
if (CorrectClick == 1)
{
pb_1.Visible = false; }
pbColors(sender, e);
}
}
Comment