Results 1 to 8 of 8

Thread: [RESOLVED] [2005] Disable letters in textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    87

    Resolved [RESOLVED] [2005] Disable letters in textbox

    hi guys,
    how could I disable letters and special characters in a textbox?

    This is simple for you guys, please help..
    thanks.. ^_^
    I Hope I Could be Great Like You

  2. #2
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Disable letters in textbox

    Code:
            private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (!(char.IsControl(e.KeyChar) || char.IsDigit(e.KeyChar) || e.KeyChar == '.'))
                {
                    e.Handled = true;
                }
            }

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    87

    Re: [2005] Disable letters in textbox

    i tried to use in C# but unfortunately the code youve given didnt work. But when I convert it to a vb code, it works well,
    what will be the problem??
    I Hope I Could be Great Like You

  4. #4
    Frenzied Member
    Join Date
    Mar 2006
    Location
    Pennsylvania
    Posts
    1,069

    Re: [2005] Disable letters in textbox

    hm? really? what's the error?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    87

    Re: [2005] Disable letters in textbox

    there's no error, but nothing happens,
    I Hope I Could be Great Like You

  6. #6
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: [2005] Disable letters in textbox

    C# is different than VB.NEt when it comes to handling events. You actually have to write the code for creating the Event Handler for the events. Check if youhave this statement in your code for InitializeComponent
    Code:
    this.textBox1.KeyPress += new System.EventHandler(this.textBox1_KeyPress);
    Or else select the text box in design mode, press F4 and in the Properties window select the lightning icon in the toll bar, this will show the events, double click the KeyPress and it will automatically create the event handler for you.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Disable letters in textbox

    Further to what Shuja Ali posted, if you already have the method written then you can select it from the drop-down list for the desired event in the Properties window.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jan 2006
    Posts
    87

    Re: [2005] Disable letters in textbox

    ahh ok.. thanks.. now I know,,
    thank you very much.,,
    I Hope I Could be Great Like You

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