Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8461023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:45:56+00:00 2026-06-10T13:45:56+00:00

Say I have NumericUpDown with Maximum = 99 and Minimum = -99 and initial

  • 0

Say I have NumericUpDown with Maximum = 99 and Minimum = -99 and initial value = 23. If user sets focus to this contol and inputs 1 (that would be 123 now) it changes it’s value to 99.
How do I keep 23 instead changing value to maximum allowed?

I tried to catch KeyDown and KeyPress, but value wasn’t changed during this events. Also I tried to implement a workaround explained in this question, but not succeeded. Validating event occurs only on leaving control. I need to simply ignore user input if it’s greater than Maximum or lesser than Minimum.

UPD. I’m using WinForms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:45:58+00:00Added an answer on June 10, 2026 at 1:45 pm

    Ok, I found solution with this question help. I tried many combinations and found one that wasn’t too complicated. I save old value on KeyDown event and check it on textBox.TextChanged event. At that time value haven’t changed yet. Now numericUpDown visually discards input that will be not in Minimum…Maximum range. Not user-friendly I think, there is some work to do.

    public partial class Form1
    {
       private decimal _oldValue;
       private TextBox textBox;
    
       public Form1()
       {
          InitializeComponent();
    
          textBox = (TextBox)numericUpDown.Controls[1];
          textBox.TextChanged += TextBoxOnTextChanged;
       }
    
       private void TextBoxOnTextChanged(object sender, EventArgs eventArgs)
        {
            decimal newValue = Convert.ToDecimal(((TextBox) sender).Text);
            if (newValue > numericUpDown.Maximum || newValue < numericUpDown.Minimum)
                ((TextBox) sender).Text = _oldValue.ToString();
        }
    
       private void numericUpDown_KeyDown(object sender, KeyEventArgs e)
       {
          _oldValue = ((NumericUpDownCustom) sender).Value;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a LINQ-to-XML query that generates an anonymous type like this: var
Say I have a higher kinded type SuperMap[Key[_],Value[_]]`. Suppose now that I had something
I have a form with a System.Windows.Forms.NumericUpDown control. Say that the range is from
Lets say have this immutable record type: public class Record { public Record(int x,
Say I have a SSI script that uses exec, or a PHP script that
Say I have this: private list<myClass> myCollection; Is there a programming idiom to shorten
Say I have a SqlAlchemy model something like this: from sqlalchemy.ext.declarative import declarative_base from
Say I have two types of objects, Apples and Chainsaws . A user is
say i have the 3 non blocking sends like this MPI_Isend (); MPI_Isend ();
Say I have an Intent like this: Intent intent = new Intent(context, MyActivity.class); I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.