[C#] A TextBox that only accepts decimal/floating/double numbers

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 ก.พ. 2025

ความคิดเห็น • 62

  • @vorapobautomation9760
    @vorapobautomation9760 5 หลายเดือนก่อน

    How to set textbox can both read and write value ?

  • @keppu2661
    @keppu2661 6 ปีที่แล้ว +1

    how to limit decimal place to 2 only while keypress?

  • @jvernice
    @jvernice 3 ปีที่แล้ว

    THANK YOU for a really simple solution that I have been looking for to validate my floating point text box.

  • @888mrxxx
    @888mrxxx 11 ปีที่แล้ว

    How can i implement you code in WPF C#? Thank you so much if you can help....

  • @pkspence
    @pkspence 11 ปีที่แล้ว

    I've got a minor modification that will only allow 2-digits after the decimal point, without a regex and no for loop. Can't cut 'n past, too many characters. Drop me a line if you're interested.

  • @kennethstanley7438
    @kennethstanley7438 10 ปีที่แล้ว

    Best answer I have found so far. Good job

  • @caffo77
    @caffo77 9 ปีที่แล้ว

    Nice, but what about negative numbers? I came up with the following code, which toggle the negative symbol when minus is pressed. The caret (prompt) is always sent at the end of the string.
    if (ch == '-')
    {
    if (Text.Length != 0 && Text[0] == '-')
    {
    Text = Text.Substring(1); //If we have a minus as first character, it removes it
    }
    else
    {
    Text = "-" + Text;
    }
    SelectionStart = Text.Length; //These 2 lines send the caret/prompt at the end of the string
    SelectionLength = 0; //Apparently superfluous, but it doesn't harm
    e.Handled = true;
    }

  • @oscarbautista4156
    @oscarbautista4156 3 ปีที่แล้ว

    Amazing solution to capture prices, thanks dude

  • @andrewtruckle1695
    @andrewtruckle1695 10 ปีที่แล้ว

    Very helpful. Thank you. It might be usefult o allow for a hyper for negative numbers.
    One thing it would be nice to cater for is if the user "pastes" into the control. It will let us paste text content in.
    Also, what if we wanted to use this on more than one control. Can we somehow turn it into a control sow e don't replicate code?
    Thanks.

    • @hammadmalik322
      @hammadmalik322 5 ปีที่แล้ว

      Did u find a solution to this?

  • @laijamanuel
    @laijamanuel 11 ปีที่แล้ว +2

    this is what I was looking for, thanks

  • @semderoos123
    @semderoos123 8 ปีที่แล้ว

    Nice video! Can you tell me how to add a comma to the filter?

  • @dutchknexman
    @dutchknexman 12 ปีที่แล้ว

    my e.KeyChar doesnt work :S how can i fix that , it gives a error and evrything is right

  • @smartcode1325
    @smartcode1325 7 ปีที่แล้ว

    HOW I MAKE A TEXTBOX THAT ACCEPT ONLY EMAIL?

  • @nealdorelis5703
    @nealdorelis5703 2 ปีที่แล้ว

    Hi Charmy, It's a great video. I like it. do have video on how to convert number no c# database to string and display no windows form ? other question, do you also have video on how to display graph from database in c# using SQL Server

  • @fairecitta
    @fairecitta 11 ปีที่แล้ว +1

    ty a lot. Would like to know how to allow only 2-digits after the decimal point.
    but it was really helpfull. ^^

  • @electrious_46
    @electrious_46 4 ปีที่แล้ว +1

    Thanks A lot man !!!

  • @nguyenquyetthang8381
    @nguyenquyetthang8381 3 ปีที่แล้ว

    That very helpful, thanks very much.

  • @rahulchowdarypinnaka
    @rahulchowdarypinnaka 4 ปีที่แล้ว

    That's really helpful. Thank you so much.

  • @caveman4191
    @caveman4191 2 ปีที่แล้ว

    thanks! it helped me alot!

  • @JsRatteChannel
    @JsRatteChannel 12 ปีที่แล้ว

    Make sure that you use the KeyPress event and not the KeyDown event.

  • @aemarco
    @aemarco 8 ปีที่แล้ว +1

    Thanks for the easy solution ;)
    --> You should use CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator[0] instead of checking for a dot-char, because in other cultures e.g. in german it will be the ',' char for commas
    alternative:
    private void breiteQuer_KeyPress(object sender, KeyPressEventArgs e)
    {
    double result;
    char c = (char)e.KeyChar;
    string text = tb.Text + c;
    if (c != (char)Keys.Back && !double.TryParse(text, out result))
    {
    e.Handled = true;
    }
    }

  • @paulvaz5846
    @paulvaz5846 10 ปีที่แล้ว

    simple and nice, thanks for your grateful help... cheers

  • @iffi786
    @iffi786 9 ปีที่แล้ว

    Thanks for a simple solution.

  • @didierleprince6106
    @didierleprince6106 6 ปีที่แล้ว

    Thanks a lot from France

  • @marcinmalacz518
    @marcinmalacz518 4 ปีที่แล้ว

    If Textbox have . yet your example permit put other .

  • @viqUni
    @viqUni 10 ปีที่แล้ว

    Thanks bro! it was helpful to me

  • @petrolheadsa
    @petrolheadsa 11 ปีที่แล้ว

    Great explanation thanks

  • @zoltrixzoltrix
    @zoltrixzoltrix 12 ปีที่แล้ว

    It's Very Helpful. Thank You

  • @Kishara101
    @Kishara101 5 ปีที่แล้ว

    Thanks 😀

  • @uliseseduardofuentesvenado7112
    @uliseseduardofuentesvenado7112 11 ปีที่แล้ว

    Great! Thanx. Really Helpful!

  • @KryptonPix
    @KryptonPix 11 ปีที่แล้ว

    Wonderful, thank you for sharing this.

  • @kirubhakarpoornam
    @kirubhakarpoornam 8 ปีที่แล้ว +1

    Thanks, Fine -!!! easy solution for hard problem

  • @CharnyCoding
    @CharnyCoding  12 ปีที่แล้ว

    Get the ASCII code of '-' and add it to the condition!

  • @duchoang5114
    @duchoang5114 4 ปีที่แล้ว

    Thanks a lot, it's helpfull :thumbup:

  • @CarlosHernandez-eu8wi
    @CarlosHernandez-eu8wi 3 ปีที่แล้ว

    Thank you for sharing you knwlege

  • @Sefree6
    @Sefree6 11 ปีที่แล้ว

    Great video.

  • @kshitijbali6915
    @kshitijbali6915 4 ปีที่แล้ว

    it helped. Thanks

  • @sbasalan
    @sbasalan 10 ปีที่แล้ว

    Amazing.. Thanks a lot

  • @raihanul2602
    @raihanul2602 11 ปีที่แล้ว +1

    totally cool !

  • @sergiopalazzi6033
    @sergiopalazzi6033 6 ปีที่แล้ว

    Many thanks!

  • @alexssandrolima
    @alexssandrolima 9 ปีที่แล้ว

    Muito bom, bem aproveitado.

  • @marcosfalconi2765
    @marcosfalconi2765 5 ปีที่แล้ว

    thank you

  • @ProgramaInventarios
    @ProgramaInventarios 9 ปีที่แล้ว

    Thank you so much

  • @zal6616
    @zal6616 9 ปีที่แล้ว

    Awesome!

  • @markvanwagoner4609
    @markvanwagoner4609 11 ปีที่แล้ว

    very nice! thx!! saved me an hour

  • @АйсилиКайбарова-г7д
    @АйсилиКайбарова-г7д 3 ปีที่แล้ว

    Спасибо большое))

  • @benmuhza3283
    @benmuhza3283 10 ปีที่แล้ว

    Many thanks

  • @Harvinder864
    @Harvinder864 10 ปีที่แล้ว

    Thanks Bro...

  • @valdeirjubertoni
    @valdeirjubertoni 9 ปีที่แล้ว

    Excelent!

  • @elginrepuela
    @elginrepuela 11 ปีที่แล้ว

    excellent...

  • @joa1paulo_
    @joa1paulo_ 9 ปีที่แล้ว

    Thanks!

  • @brv0102
    @brv0102 7 ปีที่แล้ว

    thanks bro!

  • @illmtoloko
    @illmtoloko 9 ปีที่แล้ว

    thank you dude

  • @sagarjadhav-fo9vu
    @sagarjadhav-fo9vu 7 ปีที่แล้ว

    Thanks, Bro!!!...Sooo..Simle

  • @Linkk2011
    @Linkk2011 9 ปีที่แล้ว

    thanks man =)

  • @sevashpun
    @sevashpun 11 ปีที่แล้ว

    Thanks! =)

  • @mesaytesfa9875
    @mesaytesfa9875 6 ปีที่แล้ว

    excellent

  • @fairecitta
    @fairecitta 11 ปีที่แล้ว

    i need it n.n

  • @dasarislavo
    @dasarislavo 10 ปีที่แล้ว

    thanks man

  • @zaminhassnain7570
    @zaminhassnain7570 6 ปีที่แล้ว

    Awesome (y)