Click here to Skip to main content
15,890,512 members
Articles / Programming Languages / C#

Yet Another Custom Currency Box

Rate me:
Please Sign up or sign in to vote.
2.85/5 (14 votes)
23 May 2009CPOL 54.8K   1.1K   24   14
Control that only allows numeric inputs
Sample Image - CurrencyBox.gif

Introduction

Trying to make my first custom control, I decided to build a textbox that will only allow numeric inputs. So I searched on the internet and found a very good control (NumericBox). I try to reproduce it to include it in my new personal custom controls library.

Help

  1. Use "," or "." to put the cursor before or after a decimal separator.
  2. "-" if enabled negative numbers add a minus sign.
  3. "+" Convert negative number to positive.
  4. BackSpace, erase the integer part of the number.
  5. Del, erase the decimal part of the number.

Thanks to

  • ProSoft for the great idea

Update

  • 24/05/2009: Enhancement
    • Added MaxValue and MinValue properties
    • Added ShowThousand separator property
  • 28/01/2007: Fixed Bugs
    • Deleting a number with backspace, the control eliminates two numbers

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Spain Spain
Graduado de Ingenieria Mecánica en la Cujae (2001),
Universidad de la Habana, Cuba

Comments and Discussions

 
QuestionSelect text on got focus event Pin
MCAST7610-Dec-11 5:42
MCAST7610-Dec-11 5:42 
GeneralI have Convert this Code Into VB but it doesn't work can u help me??? Pin
SunLucDong16-Apr-11 21:13
SunLucDong16-Apr-11 21:13 
GeneralHindi Numbers Pin
PeaceTiger6-Nov-10 10:22
PeaceTiger6-Nov-10 10:22 
GeneralRe: Hindi Numbers Pin
PeaceTiger6-Dec-10 21:03
PeaceTiger6-Dec-10 21:03 
GeneralMy vote of 5 Pin
PeaceTiger15-Oct-10 15:25
PeaceTiger15-Oct-10 15:25 
GeneralNice control but i experienced some weird issues Pin
Member 25738317-Jan-10 6:35
Member 25738317-Jan-10 6:35 
The problem im talkin about occures often after massive key pressing on focused Currency box. I dunno why but when i press a digit key and hold it for a long while i got something looks like GDI crash or something Smile | :) and ofcourse application crash after this. Below i paste some error reports from Windows 7 and XP. I suppose this problem is related to onpaint event within currencybox.dll

****** Windows 7 *******

Description:
Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: program.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4b45f476
Problem Signature 04: System.Drawing
Problem Signature 05: 2.0.0.0
Problem Signature 06: 4a275e83
Problem Signature 07: 184
Problem Signature 08: 20
Problem Signature 09: System.ArgumentException
OS Version: 6.1.7600.2.0.0.256.48
Locale ID: 1045

Read our privacy statement online:
http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
C:\Windows\system32\en-US\erofflps.txt

********Windows XP*************************

System.ArgumentException was unhandled
Message="Parameter is not valid."
Source="System.Drawing"
StackTrace:
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)
at System.Drawing.Bitmap..ctor(Int32 width, Int32 height)
at System.Drawing.Icon.ToBitmap()
at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
at System.Windows.Forms.Control.WndProcException(Exception e)
at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Program.Program.Main() in G:\Program.cs:line 23

I looked deeper into the source code and tried to diagnose what is goin on but i was not able to.
What could it be ?
GeneralMnemonics issue Pin
Eric Marin15-Oct-09 5:02
Eric Marin15-Oct-09 5:02 
GeneralPocket PC project Pin
PGuimaraes3-Sep-08 4:07
PGuimaraes3-Sep-08 4:07 
GeneralThanks Pin
DALAS_<><>14-Jun-07 23:11
DALAS_<><>14-Jun-07 23:11 
GeneralChange to to control Pin
hardsoft14-Jun-07 9:54
hardsoft14-Jun-07 9:54 
GeneralBut it's in C# Code not C++ Pin
Nacereddine29-Jan-07 1:20
professionalNacereddine29-Jan-07 1:20 
GeneralThank you! Pin
MCAST7626-Jan-07 7:12
MCAST7626-Jan-07 7:12 
GeneralRe: Thank you! Pin
Juan Manuel Elosegui28-Jan-07 4:12
Juan Manuel Elosegui28-Jan-07 4:12 
GeneralRe: Thank you! Pin
MCAST7628-Jan-07 13:52
MCAST7628-Jan-07 13:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.