Results 1 to 3 of 3

Thread: Intercepting Keys

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Intercepting Keys

    This is what I want to do:

    Code:
    if (!Char.IsDigit(e.KeyChar.ToString(), 0) )
    {
        STOPTHISCHARFROMBEINGENTERED();
    }
    but e.KeyChar can't be assigned to bc it's readonly.

    Help?

    Dan

  2. #2
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877

    Re: Intercepting Keys

    Quote Originally Posted by dipique
    This is what I want to do:

    Code:
    if (!Char.IsDigit(e.KeyChar.ToString(), 0) )
    {
        STOPTHISCHARFROMBEINGENTERED();
    }
    but e.KeyChar can't be assigned to bc it's readonly.

    Help?

    Dan

    Simply use e.Handled=true

    Code:
    private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    		{
    			if (!Char.IsDigit(e.KeyChar.ToString(), 0) )
    			{
    				e.Handled=true;
    			}
    		}
    Dan

    My username elsware is datique which is very similar to you. We are not long lost brothers are we. Lol
    [VBF RSS Feed]

    There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.

    If I have been helpful, Please Rate my Post. Thanks.

    This post was powered by :

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2005
    Posts
    31

    Thumbs up Re: Intercepting Keys

    Thanks, that worked wonderfully. As to whether we are long lost brothers... well, I suppose it's possible. But probably not

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