Numeric UpDown

F

Ferdinand Zaubzer

Hello
I would like to set a NumericUpDown control to readonly and I don't want
it to response on klicks on the arrows.
I set the ReadOnly property to false and the InterceptArrowKeys to false
too.

myNumericUpDown.ReadOnly = false;
myNumericUpDown.InterceptArrowKeys = true;

The result is that the control looks like ReadOnly but the arrow buttons
still work and can change the value. And I think this shouldn't be
possible.

Thanks
Ferdinand
 
B

Bruce Wood

From the documentation for UpDownBase.ReadOnly:

"true if the text can be changed by the use of the up or down buttons
only; otherwise, false. The default value is false."

"By setting the ReadOnly property to true, you will eliminate the need
for much validation of the Text property. The user will be restricted
to the use of the up and down buttons to change the Text values. It
will only allow them to select values you specify."

So, basically, the ReadOnly property doesn't do what you think it does
(or, for that matter, what the name implies that it does... stupid
behaviour for a property named ReadOnly, IMHO, but there you go).
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
F

Ferdinand Zaubzer

But with InterceptArrowKeys set to false it is still changable with the
Arrowkeys.
I don't want to Use enabled=false becuase then you cannot copy the
number to paste it somewhere else.

Thanks
Ferdinand
 
B

Bruce Wood

Let's back up a second, here.

A read-only text box that the user can't modify is really just a
ReadOnly TextBox with some useless buttons beside it. Why, exactly, do
you want those useless buttons there?

The only thing that comes to my mind is that you want a value that the
user can change in some situations, but which is read-only in other
situations. If that's the case, then there's an easy solution.

Place _two_ controls that that place on your form. One, a NumericUpDown
control; the other, a TextBox with ReadOnly set to true. Populate both
with your value, all the time. When you want the user to be able to
manipulate the value, Hide() the TextBox and Show() the NumericUpDown
control. When you want it to be read-only, Show() the TextBox and
Hide() the NumericUpDown control.

If you really want to be clever, create a UserControl of your own that
contains a NumericUpDown control and a TextBox that act this way
depending upon the setting of the ReadOnly property on your
UserControl. Lots more work, though, as you have to reproduce the
public contract of the NumericUpDown in your UserControl.

I wouldn't bother trying to bend NumericUpDown to your will. Just play
tricks behind the scenes to use a different control in ReadOnly
situations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top