CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2008
    Location
    Step Into(F11)
    Posts
    465

    Question KeyPress Event Issue

    Can anyone tell me ???Why KeyPress Event is Not working .when I press enter .It Does not go in the KeyDown event(Where i did breakpoint) during debugging.let me know the idea. Any help would be highly appreciated !!!
    Code:
    private void TxtPumpNo1A_Keydown(object sender, System.Windows.Forms.KeyEventArgs e){
                if (e.KeyCode == Keys.Return){
                    double val = 0;
                    try{                
                        val = double.Parse(TxtPumpNo1A.Text);
                    }
                    catch{
                        MessageBox.Show("PumpNo1A Cannot be Text");
                        TxtPumpNo1A.Text=string.Empty;
                        TxtPumpNo1A.Focus();
    
                    }
    

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: KeyPress Event Issue

    Of course we can't tell you because you have not given us a complete code sample. Where is that method assigned to the KeyDown event of your textbox. The fact that the "d" in your method signature is lowercase indicates that the event was not generated automatically by the IDE (either in the code window or through the Properties window).

  3. #3
    Join Date
    Oct 2010
    Posts
    11

    Re: KeyPress Event Issue

    void button1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if (e.KeyChar.Equals((char)13)) //(char)13 = "Retrun/Enter" on English Standard keyboards
    {
    //do something;
    }
    }

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: KeyPress Event Issue

    Good call crash, but you can just use Keys.Enter.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured