Results 1 to 4 of 4

Thread: Need help with overriding OnKeypress in windows phone 7

  1. #1
    Join Date
    Oct 2011
    Posts
    108

    Need help with overriding OnKeypress in windows phone 7

    I am using a windows phone 7(mango) and I have made a code in order to restrict textbox input to only digits but it is not working with the wp7 I don’t know where I am going wrong and I think that there is something missing in it but I am not getting it as I am new to C#. So is there anyone who has an idea about it and can help me out with as well. Any suggestion regarding this will be highly appreciated.
    protected override void OnKeypress(KeyEventArgs a)

    {
    base.OnKeyDown(a);

    if (char.IsDigit(Convert.ToChar(a.Key)))
    {

    }
    else
    {
    a.Handled = true;
    }
    }

  2. #2
    Join Date
    May 2011
    Posts
    97

    Re: Need help with overriding OnKeypress in windows phone 7

    I think that you can try this out:
    private void textBox1_Keypress(object sender, KeyEventArgs a) {

    if (e.PlatformKeyCode >= 48 && e.PlatformKeyCode <= 57) {
    System.Diagnostics.Debug.WriteLine("digit: " + a.Key);
    } else {
    System.Diagnostics.Debug.WriteLine("letters: " +a.Key);
    a.Handled = true;
    }


    }
    Just check it out and then let me know if it works for you.

  3. #3
    Join Date
    May 2011
    Posts
    102

    Re: Need help with overriding OnKeypress in windows phone 7

    You can try this one as well:
    protected override void OnKeypress(KeyEventArgs a)
    {
    base.OnKeypress(a);

    if (a.Key == Key.D0 || a.Key == Key.D1 || a.Key == Key.D2 || a.Key == Key.D3 || a.Key == Key.D4 || a.Key == Key.D5 || a.Key == Key.D6 || a.Key == Key.D7 || a.Key == Key.D8 || a.Key == Key.D9 || a.Key == Key.Decimal)
    {
    }
    else
    {
    a.Handled = true;
    }
    }

  4. #4
    Join Date
    Nov 2011
    Posts
    111

    Re: Need help with overriding OnKeypress in windows phone 7

    I have tried this code out but then I will like to inform you that the above codes are not able to stop the keys like !#&$.I think that they have same PlatformKeyCode and the key values as numbers.I just wanted to know that have you found any error in the emulator or something or it is just a problem of the platform. Any help regarding this will be appreciated.

Similar Threads

  1. Replies: 5
    Last Post: 03-08-2013, 11:08 AM
  2. Replies: 8
    Last Post: 28-09-2011, 04:20 PM
  3. Stop firefox from overriding the homepage
    By Augustine in forum Technology & Internet
    Replies: 3
    Last Post: 02-03-2011, 05:59 AM
  4. Windows 7 Scan Overriding Canon MX310
    By flosamuels in forum Operating Systems
    Replies: 1
    Last Post: 27-11-2010, 08:35 AM
  5. Overriding and Shadowing in C#
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 01-02-2010, 07:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,017,686.33608 seconds with 17 queries