Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with my numeric text box user control

Problem with my numeric text box user control

Scheduled Pinned Locked Moved C#
csharphelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anu Palavila
    wrote on last edited by
    #1

    Hai Me with C#.net I want to make a text box to accept only numbers and decimal points(decimal point only once), so I tried to make a user control and is working fine except one problem. If if select all the data in the text box and try to enter a new value decimal point will not accept until I press the backspace. My user control code is a follows string i; int f; public string Text { get { return NMTextBox.Text; } set { NMTextBox.Text = value; } } private void NMTextBox_KeyPress(object sender, KeyPressEventArgs e) { try { string numaric = NMTextBox.Text; for (int j = 0; j < numaric.Length; j++) { char myChar = numaric[j]; } if (NMTextBox.Text == "") { f = 0; } if (e.KeyChar.ToString() == ".") { ++f; if (f >= 2) { e.Handled = true; } } if (i == "8") { f = 0; for (int j = 0; j < numaric.Length - 1; j++) { if (numaric[j].ToString() == ".") { ++f; } } } if (e.KeyChar.ToString() != "." && Char.IsNumber(e.KeyChar) != true) { if (i != "8") { e.Handled = true; } } } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message.ToString()); } } private void NMTextBox_KeyDown(object sender, KeyEventArgs e) { i = e.KeyValue.ToString(); }

    Thanks & Regards

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups