Numeric edit and numeric spin controls
Posted
by T. VU KHAC
on February 2nd, 1999
In my application I needed an edit control which accepts only numeric numbers. In many science applications this is indispensable, but it is actually not implemented in MS-Visual C/C++. It is not difficult to implement this control and I see that some people implemented it. In my own code, some new features were enriched as error messages and range defines, etc.Note: to use the CNumEdit class properly, the ES_NUMBER, ES_MULTILINE must not be set.
Another control added in my work is CNumSpinCtrl which enables using a spin control as a numeric one which is also not implemented in MFC.
Note: to use the CNumSpinCtrl class properly, the ES_AUTOBUDDY, ES_SETBUDDYINTEGER must not be set.
Your suggestions are appreciated. Enjoy!
class CNumEdit : public CEdit
{
DECLARE_DYNAMIC(CNumEdit)
public:
CNumEdit();
virtual ~CNumEdit();
enum {VALID = 0x00, OUT_OF_RANGE = 0x01, INVALID_CHAR = 0x02};
virtual void ChangeAmount(int step);
virtual float GetDelta();
virtual void SetDelta(float delta);
virtual void GetRange(float &min, float &max)const;
virtual void SetRange(float min, float max);
virtual void Verbose(BOOL v);
virtual BOOL Verbose()const;
virtual int IsValid()const;
virtual int IsValid(const CString &str)const;
virtual BOOL SetValue(float val);
virtual float GetValue()const;
protected:
virtual CString& ConstructFormat(CString &str, float num);
BYTE m_NumberOfNumberAfterPoint;
BOOL m_Verbose;
float m_Delta, m_MinValue, m_MaxValue;
DECLARE_MESSAGE_MAP()
};
class CNumSpinCtrl : public CSpinButtonCtrl
{
DECLARE_DYNAMIC(CNumSpinCtrl)
public:
CNumSpinCtrl();
virtual ~CNumSpinCtrl();
virtual void SetDelta(float delta);
virtual float GetDelta();
virtual void SetBuddy(CNumEdit *edit);
virtual CNumEdit* GetBuddy() const;
virtual void GetRange(float &lower, float& upper ) const;
virtual void SetRange(float nLower, float nUpper );
virtual float GetPos();
virtual void SetPos(float val);
};
Date Last Updated: May 17, 1999

Comments
Float edit control in C#
Posted by yagnesh on 01/20/2005 04:27amHow to make my own float edit text box in c#. It should work based on masking provided. e.g. if ####.## is a mask then 1234.56 should accept not 12.3345. Plz mail me the solution on yagneshpatel.windowmaker.com
Replyhow to use
Posted by Legacy on 05/07/2001 12:00amOriginally posted by: Julia
Do you mind telling me how to use your class in viewform?
Thank you very much,
Julia
ReplyThank's
Posted by Legacy on 12/21/2000 12:00amOriginally posted by: Flo
ReplyNumeric edit and numeric spin controls
Posted by Legacy on 12/12/1999 12:00amOriginally posted by: Pilar Garc�a
Excellent! I have tried with usual Edit and CSpinButtonCtrl controls but your classes are much better. With the first, the edit box must be "only read", for example.
I�m learning much with codeguru. Thank you very much!
Reply/editctrl/NumericSpin.shtml
Posted by Legacy on 06/10/1999 12:00amOriginally posted by: Julie Dinh
Hi!! I was looking at codeguru and found your article...
I am sorry but "are u vietnames???" ...your name kindda looks like one....anyway...back to the question...
"how do u disable a CEdit"...that is you have a small edit
box....if the edit box is not in used...i want to disable it or greyed it out...but i don't know how...so ....heeeeelp...
your reply is truly appreciated....
ReplyJulie
Modification for wrap, minus, and decimal
Posted by Legacy on 04/29/1999 12:00amOriginally posted by: Corey McKenzie
Reply