I'm using a number of NumericUpDown controls on my form, which controls
printer settings such as number of pages.
However I want to override one of the default behaviours of the control,
namely when it is tabbed into (selected), I want the number that is displayed
in it to become selected, so the user can just type straight over it.
For this I'm using the event handler:
private void UpDown_Enter(ob ject sender, System.EventArg s e)
{
NumericUpDown n = (NumericUpDown) sender;
n.Select(0, n.Value.ToStrin g().Length);
}
I notice that the NumericUpDown only has a Value property, which is a
decimal, but will the ToString method of this always give the text that is
actually displayed in the control? i.e. will this be robust? 10 7145
Bonj <Bo**@discussio ns.microsoft.co m> wrote: I notice that the NumericUpDown only has a Value property,
Actually, it also has a Text property: http://msdn.microsoft.com/library/de...stexttopic.asp
which is a decimal, but will the ToString method of this always give the text that is actually displayed in the control?
Well, when calling the get-accessor of the Value property, the control
validates the content and updates the visible text if necessary. For
example, if someone pasted some non-numerical data into the control (yes,
it's possible), then when you call the get-accessor of Value, the control's
text will change after validation failed.
However, since the text is updated before the value is returned from the
get-accessor, calling ToString on the returned value should always give you
a string with the same value as the control's visible text at that point in
time.
i.e. will this be robust?
I believe so.
In any case, for what you're doing, it's probably more logical to use the
Text property which simply retrieves the text from the TextBox-derived
control used internally by the NumericUpDown.
excellent, thanks
"C# Learner" wrote: Bonj <Bo**@discussio ns.microsoft.co m> wrote:
I notice that the NumericUpDown only has a Value property,
Actually, it also has a Text property: http://msdn.microsoft.com/library/de...stexttopic.asp
which is a decimal, but will the ToString method of this always give the text that is actually displayed in the control?
Well, when calling the get-accessor of the Value property, the control validates the content and updates the visible text if necessary. For example, if someone pasted some non-numerical data into the control (yes, it's possible), then when you call the get-accessor of Value, the control's text will change after validation failed.
However, since the text is updated before the value is returned from the get-accessor, calling ToString on the returned value should always give you a string with the same value as the control's visible text at that point in time.
i.e. will this be robust?
I believe so.
In any case, for what you're doing, it's probably more logical to use the Text property which simply retrieves the text from the TextBox-derived control used internally by the NumericUpDown.
That actually raises another interesting question - how do you implement that
in a derived class whereby it "gets rid" of one of the properties of the base
class?
For example, i have some controls that are derived from comboboxes, but they
make no sense if they are not owner drawn, so I want to make the DrawMode
property inaccessible, whereas it is accessible in the combobox, so it
propogates through to my derived class. So is it possible to "get rid" of it,
like the NumericUpDown has "got rid" of the Text property?
"C# Learner" wrote: Bonj <Bo**@discussio ns.microsoft.co m> wrote:
I notice that the NumericUpDown only has a Value property,
Actually, it also has a Text property: http://msdn.microsoft.com/library/de...stexttopic.asp
which is a decimal, but will the ToString method of this always give the text that is actually displayed in the control?
Well, when calling the get-accessor of the Value property, the control validates the content and updates the visible text if necessary. For example, if someone pasted some non-numerical data into the control (yes, it's possible), then when you call the get-accessor of Value, the control's text will change after validation failed.
However, since the text is updated before the value is returned from the get-accessor, calling ToString on the returned value should always give you a string with the same value as the control's visible text at that point in time.
i.e. will this be robust?
I believe so.
In any case, for what you're doing, it's probably more logical to use the Text property which simply retrieves the text from the TextBox-derived control used internally by the NumericUpDown.
Bonj <Bo**@discussio ns.microsoft.co m> wrote: That actually raises another interesting question - how do you implement that in a derived class whereby it "gets rid" of one of the properties of the base class?
You can't, really. The closest you can get is to create a new public
member with the same name as the inherited one, thus "hiding" the inherited
member. See <http://www.yoda.arachs ys.com/csharp/faq/#override.new> for
details.
For example, i have some controls that are derived from comboboxes, but they make no sense if they are not owner drawn, so I want to make the DrawMode property inaccessible, whereas it is accessible in the combobox, so it propogates through to my derived class. So is it possible to "get rid" of it,
Not through inheritance, no. You could use encapsulation to achieve this,
however -- create a UserControl which contains the particular control and
only expose certain members of that control.
like the NumericUpDown has "got rid" of the Text property?
NumericUpDown didn't get rid of it. However, it apparently decorated the
member with some attributes which cause it to not show up in the form
designer property grid and to not show up in intellisense.
Try compiling:
MessageBox.Show (myNumericUpDow n.Text);
and you'll see that it does in fact exist. :-)
Bonj,
Why not use the Text property? I would assume that it would return the
actual text in the window, and not whatever is returned by ToString. You
can't always use ToString, because if a format is applied to the number (say
there are separators like commas for every three digits), then the text in
the box will be different from what is returned from ToString.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Bonj" <Bo**@discussio ns.microsoft.co m> wrote in message
news:52******** *************** ***********@mic rosoft.com... I'm using a number of NumericUpDown controls on my form, which controls printer settings such as number of pages. However I want to override one of the default behaviours of the control, namely when it is tabbed into (selected), I want the number that is displayed in it to become selected, so the user can just type straight over it. For this I'm using the event handler:
private void UpDown_Enter(ob ject sender, System.EventArg s e) { NumericUpDown n = (NumericUpDown) sender; n.Select(0, n.Value.ToStrin g().Length); }
I notice that the NumericUpDown only has a Value property, which is a decimal, but will the ToString method of this always give the text that is actually displayed in the control? i.e. will this be robust?
> Bonj, Why not use the Text property?
Because I wasn't thinking out of the box - the Text property is a property
of the base class (UpDownBase), and not a property of the actual
NumericUpDown control. Now I know to cast to UpDownBase, I can retrieve the
Text property no problem.
I would assume that it would return the actual text in the window, and not whatever is returned by ToString. You can't always use ToString, because if a format is applied to the number (say there are separators like commas for every three digits), then the text in the box will be different from what is returned from ToString.
Exactly, that's precisely what I was hoping to avoid. But I think I have
done, as if you put non-numeric values into it, then it still replaces it
with either zero or what was in there before and doesn't throw any
exceptions, so I'm happy with it. NumericUpDown didn't get rid of it. However, it apparently decorated the member with some attributes which cause it to not show up in the form designer property grid and to not show up in intellisense.
Yeah - that would be enough, for it not to show up in intellisense. I don't
actually *need* to get rid of it, as in absolutely require its death beyond
all circumstances. It would just be nice to know you're not supposed to use
it.
Any idea how you do that? Try compiling:
MessageBox.Show (myNumericUpDow n.Text);
and you'll see that it does in fact exist. :-)
Bonj <Bo**@discussio ns.microsoft.co m> wrote: Why not use the Text property?
Because I wasn't thinking out of the box - the Text property is a property of the base class (UpDownBase), and not a property of the actual NumericUpDown control. Now I know to cast to UpDownBase, I can retrieve the Text property no problem.
Text *is* a member of NumericUpDown, and it overrides UpDownBase.Text .
Try:
MessageBox.Show (myNumericUpDow n.Text); You can't always use ToString, because if a format is applied to the number (say there are separators like commas for every three digits), then the text in the box will be different from what is returned from ToString.
Exactly, that's precisely what I was hoping to avoid. But I think I have done, as if you put non-numeric values into it, then it still replaces it with either zero or what was in there before and doesn't throw any exceptions, so I'm happy with it.
But the point here is that if you were to set
NumericUpDown.T housandSeparato rs to true, for example, then the result of
Value.ToString might be different from Text (something I inadvertently
neglected to mention earlier). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: |
last post by:
Hi,
I am setting the NumericUpDown .Value property and the ValueChanged event
is NOT being fired. Does this ONLY get fired when I change it on the UI and
not programatically?
Thanks
|
by: Patrick Blackman |
last post by:
Can anyone tell me how to get the numericupdown control to support themes?
|
by: Sachin |
last post by:
On a form I have two NumericUpDown controls to show "nUdFrom" and "nUdTo"
values. I want to add validation code for the same, like value in "nUdFrom"
should alway me less than that of in "nUdTo" ,and exactly opposite validation
for "nUdTo".
I want to validate at Leave event and when Dialog close button or OK button
or Cancel button is clicked. How to use validating event effectively for the
same? or is there any other effective way?
More...
|
by: bnob |
last post by:
It is possible to format the numeric value of the NumericUpDown control
For example : display numbers in 2 digits, instead of 1 display 01, 0
-> 00 , 9 -> 09
Any idea
--
Ceci est une signature automatique de MesNews.
Site : http://www.mesnews.net
|
by: abc my vclass |
last post by:
My win-form have many numericupdown controls to applied. But numericupdown
control don't like textbox, text box control can automatic selected text
when got focus. Is there any method can let me set all numericupdown
autoselect text when gotfocus?
| |
by: tommaso.gastaldi |
last post by:
Hello,
A probably dumb question...
does anyone know hot to avoid that if one keep the mouse pressed on an
arrow of the numericUpDown it continues to fire events (it uses
evidently a timer) ?
I want 1 event for each click, and no timer activation. I have tried
using disable within the handler but does not work.
|
by: =?Utf-8?B?R3VzIENodWNo?= |
last post by:
How do I set the Maximum values of a NumericUpDown Control?
If OptionBox TermsMonths.Checked = True Then
Control.Maximum() = 360
Else
Control.Maximum() = 30
--
Thank You
Gus Chuchanis
|
by: =?Utf-8?B?U2hhcm9u?= |
last post by:
Hello experts,
I posted a disturbing question in here:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.languages.csharp&mid=dedc665f-91c0-4fa4-a103-a98a6808759c
But no one have answered it.
Is not clear? or maybe it a Framework bug?
Please help.
|
by: pamela fluente |
last post by:
My numericUpDowns show numbers in the format 1.500,56 (italy).
Instead, I need *invariantly* that they show and accept the format
1,500.56, as in the USA.
What's the right way to do that? I have tried to set the current
culture to
the US culture, but nothing changed.
For instance I tried without success (vb) :
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |