OnKeyPress

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jon Rea

    #1

    OnKeyPress

    Hi,

    First of all is there/ what is the Archive URL of this newsgroup ?



    Secondly I want to handle keypresses in my application. When i add events to
    Keydown or Keypress to the main form, the events are not triggered upon
    pressing any key ...

    Any ideas what i am doing wrong ? - see very simple code below ....

    Many thanks in advance

    Jon Rea



    // VC++ c# .net generated code

    this.KeyDown += new System.Windows. Forms.KeyEventH andler(this.onK eyDown);

    this.KeyPress += new
    System.Windows. Forms.KeyPressE ventHandler(thi s.onKeyPress);



    //function added by the event section of the properties window

    private void onKeyPress(obje ct sender,
    System.Windows. Forms.KeyPressE ventArgs e)

    {

    MessageBox.Show ("hello");

    }


  • Bob Powell [MVP]

    #2
    Re: OnKeyPress

    Try overriding ProcessCmdKey instead.

    --
    Bob Powell [MVP]
    C#, System.Drawing

    ANNOUNCING: Well Formed.
    The monthy electronic magazine for
    Windows Forms and GDI+ engineers


    Check out the GDI+ FAQ



    "Jon Rea" <jr0407@bris.ac .uk> wrote in message
    news:Xwx4b.2047 $6r4.745@news-binary.blueyond er.co.uk...[color=blue]
    > Hi,
    >
    > First of all is there/ what is the Archive URL of this newsgroup ?
    >
    >
    >
    > Secondly I want to handle keypresses in my application. When i add events[/color]
    to[color=blue]
    > Keydown or Keypress to the main form, the events are not triggered upon
    > pressing any key ...
    >
    > Any ideas what i am doing wrong ? - see very simple code below ....
    >
    > Many thanks in advance
    >
    > Jon Rea
    >
    >
    >
    > // VC++ c# .net generated code
    >
    > this.KeyDown += new System.Windows. Forms.KeyEventH andler(this.onK eyDown);
    >
    > this.KeyPress += new
    > System.Windows. Forms.KeyPressE ventHandler(thi s.onKeyPress);
    >
    >
    >
    > //function added by the event section of the properties window
    >
    > private void onKeyPress(obje ct sender,
    > System.Windows. Forms.KeyPressE ventArgs e)
    >
    > {
    >
    > MessageBox.Show ("hello");
    >
    > }
    >
    >[/color]


    Comment

    Working...