|
-
Sep 1st, 2021, 01:59 AM
#1
Thread Starter
New Member
Numeric Up Down Autosize not changing size
I'm a very low-level amateur - sorry if this is really basic (pun intended).
I have a numeric up down box that I wish to auto size the width, but autosize doesn't seem to do anything. Using VS Community. Here is some demonstration code of the problem (not the real code I'm using, but same behavior). The box just stays the same size. Shouldn't the box shrink and grow with the length of the number? Or am I misinterpreting what autosize does?
Code:
' ------- VB.net code -----------------
Public Class Form1
Dim x As ULong
Dim y As ULong
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
nubAutosize.AutoSize = True
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Application.DoEvents()
nubAutosize.Value = 1
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 10
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 1000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 10000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 100000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 1000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 10000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 100000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 1000000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 10000000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 100000000000
For y = 1 To 100000
Application.DoEvents()
Next
nubAutosize.Value = 1000000000000
For y = 1 To 100000
Application.DoEvents()
Next
End Sub
End Class
Last edited by si_the_geek; Sep 1st, 2021 at 02:53 AM.
Reason: added Code tags
-
Sep 1st, 2021, 03:25 AM
#2
Re: Numeric Up Down Autosize not changing size
It adapts the length of the box depending on the value you put in the .Maximum property but not the effective value. It is not dynamic like a label.
Last edited by Delaney; Sep 1st, 2021 at 03:28 AM.
The best friend of any programmer is a search engine 
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Sep 1st, 2021, 09:03 AM
#3
Re: Numeric Up Down Autosize not changing size
Autosize doesn't always do anything for every control. What effect are you hoping to achieve?
My usual boring signature: Nothing
 
-
Sep 1st, 2021, 01:16 PM
#4
Thread Starter
New Member
Re: Numeric Up Down Autosize not changing size
 Originally Posted by Shaggy Hiker
Autosize doesn't always do anything for every control. What effect are you hoping to achieve?
Thank you very much for the answers.
To answer your question, I was hoping to achieve having the box grow according to the number of characters in it, and shrink for less characters. It looks silly to have a huge box with four digits in it. Most of the time the user will use only a four to six digit number (a counter for a loop) but if the user wants the program to run continuously, until the stop button is pressed, the box will display the maximum value the data type is capable of. Occasionally a user may choose a very large number such as ten billion or something (a betting simulator).
An alternative would be to have the box display empty (null) or a string such as "infin" but I haven't figured out how to do either one in a nud box (not at my level of experience). It has no text property in the VB.NET Windows Forms App properties set.
-
Sep 1st, 2021, 02:06 PM
#5
Re: Numeric Up Down Autosize not changing size
A NumericUpDown can only contain numbers, so there is no option for text in it.
A fairly standard way for a user to indicate an infinite number of loop iterations is to use -1 as the value; but that doesn't look too nice. A very good alternative is to use another control (perhaps a checkbox) for "infinite", and disable the NumericUpDown if it is ticked.
-
Sep 1st, 2021, 02:43 PM
#6
Re: Numeric Up Down Autosize not changing size
Also, stay away from DoEvents. If you are thinking of a very long running loop, there is a tendency to reach for DoEvents to keep the display responsive, and it CAN be used that way effectively, but it's better not to. There can be some unexpected side effects of DoEvents, so it would be better to avoid making use of that construct.
My usual boring signature: Nothing
 
-
Sep 1st, 2021, 03:16 PM
#7
Thread Starter
New Member
Re: Numeric Up Down Autosize not changing size
 Originally Posted by si_the_geek
A NumericUpDown can only contain numbers, so there is no option for text in it.
A fairly standard way for a user to indicate an infinite number of loop iterations is to use -1 as the value; but that doesn't look too nice. A very good alternative is to use another control (perhaps a checkbox) for "infinite", and disable the NumericUpDown if it is ticked.
Thank you. That's a good idea. I'm not sure why they didn't think there might be a time we need to put in a text message or blank, but I can work with your idea quite well. Excellent suggestion.
-
Sep 1st, 2021, 03:19 PM
#8
Thread Starter
New Member
Re: Numeric Up Down Autosize not changing size
Good point. Yes, I'm aware of that and have read articles on both sides of the issue. I'm planning to replace the DoEvent for the counter with other alternatives, but I also have a checkbox for the user to turn off the live counter so the loops will run much faster.
-
Sep 1st, 2021, 08:03 PM
#9
Re: Numeric Up Down Autosize not changing size
 Originally Posted by Rzimmerman
Thank you. That's a good idea. I'm not sure why they didn't think there might be a time we need to put in a text message or blank, but I can work with your idea quite well. Excellent suggestion.
Because a NumericUpDown can only hold a number. An empty string is not a number. Technically, you can now have a nullable Decimal, but that has been a recent addition to the language. Before that, it wasn't possible to have a Decimal that was not a number, so blank wasn't an option, since the Value property of the NumericUpDown is a Decimal.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|