CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2005
    Posts
    1

    Question NumericUpDown - Number + unit

    I would like to use a NumericUpDown and add the unit (feet, ...) after the number.
    This is made by extending the NumericUpDown class and overriding the UpdateEditText method like that:
    protected override void UpdateEditText()
    {
    //Let the base component format the number according to the different properties
    base.UpdateEditText();
    //Add the unit
    base.ChangingText = true;
    base.Text = base.Text + " " + unit;
    base.ChangingText = false;
    }

    But the problem is when a user change a part of the text in the textbox,
    the ParseEditText method cannot parse a string like "2 feet",
    and i cannot override this method like it is not virtual or abstract in the base class (Why did Microsoft do that?).

    Please help me to find a solution.

    Thanks in advance

  2. #2
    Join Date
    Oct 1999
    Location
    Germany
    Posts
    121

    Re: NumericUpDown - Number + unit

    Hi yala,

    may it help to implement "numericUpDown1_Validating". So you can check the value entered in the box and evaluate it for your needs.


    Regards
    Jost

  3. #3
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    1,475

    Re: NumericUpDown - Number + unit

    From my exprerience with the NumericUpDown control - I advice you to go to different directions.
    For example: Create a UserControl, put a NumericUpDown, so the TextBox will not be visible (resize it) and only the UpDown arrows will be shown. Add a TextBox. So far, the control looks exactly like a NumericUpDown, except the arrows doesn't do anything. So catch both TextChanged of the TextBox and ValueChanged of the NumericUpDown in order to sync those two.
    Add a Value property, and a ValueChanged event, and you have got your self a fine custom NumericUpDown.

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

Featured