Override OnKeyPress Problem

  • Thread starter Thread starter ~toki
  • Start date Start date
T

~toki

How can i take the control of the key events in Class2 ?

This is the code snipped that i'd tried (after try some others):

public class Main : System.Windows.Forms.Form
{
protected virtual void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e) { /* Do Nothing */ }
}
public class Class1 : Main
{
protected override void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e) { /* Do Nothing */ }
}

public class Class2 : Class1
{
protected override void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e) { /* DO SOMETHING */ }
}
 
Call in each class the function of the base:

Class1 and 2:
protected override void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e)
{ base.OnKeyPress(sender, e); }


By the way, if you want to use the OnKeyPress method of
System.Windows.Forms.Form, it has no argument "sender" !

Class Main:
protected virtual void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e)
{ /* Do Nothing */ }

protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{ OnKeyPress(this, e); base.OnKeyPress(e); }



Jaga
 
Thanks a lot for your time, it work!

Jaga said:
Call in each class the function of the base:

Class1 and 2:
protected override void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e)
{ base.OnKeyPress(sender, e); }


By the way, if you want to use the OnKeyPress method of
System.Windows.Forms.Form, it has no argument "sender" !

Class Main:
protected virtual void OnKeyPress(System.Object sender,
System.Windows.Forms.KeyPressEventArgs e)
{ /* Do Nothing */ }

protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
{ OnKeyPress(this, e); base.OnKeyPress(e); }



Jaga
 
Back
Top