Click here to Skip to main content
16,004,919 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How to type on command window at an instance? Pin
barkanb20-Mar-07 20:58
barkanb20-Mar-07 20:58 
GeneralRe: How to type on command window at an instance? Pin
Dave Kreskowiak21-Mar-07 1:39
mveDave Kreskowiak21-Mar-07 1:39 
GeneralRe: How to type on command window at an instance? Pin
barkanb21-Mar-07 4:19
barkanb21-Mar-07 4:19 
QuestionRe: How to type on command window at an instance? Pin
barkanb21-Mar-07 7:23
barkanb21-Mar-07 7:23 
AnswerRe: How to type on command window at an instance? Pin
Dave Kreskowiak21-Mar-07 8:40
mveDave Kreskowiak21-Mar-07 8:40 
AnswerRe: How to type on command window at an instance? Pin
barkanb22-Mar-07 0:46
barkanb22-Mar-07 0:46 
GeneralRe: How to type on command window at an instance? Pin
Dave Kreskowiak22-Mar-07 2:20
mveDave Kreskowiak22-Mar-07 2:20 
QuestionNumericUpDown displays too many digits while it has focus Pin
ChrisDavidson20-Mar-07 5:50
ChrisDavidson20-Mar-07 5:50 
I have an issue where the NumericUpDown box is diplaying too many values.

I have a simple NumericUpDownBox with the minimum set to 1 and the maximum set to 4, but can enter multiple digits on the control and I need to prevent this.

By using the KeyDown event, I am able to prevent the user from entering anything but 1, 2, 3, 4, and a few special keys like backspace, left-right arrows and delete. However, I can still press 4444444 in the display box.

I tried to coerce the code to over-write the digit with any valid key pressed. For example if "1" is pressed, then the value gets set to 1. But since it's not a .text display, the display is not getting changed.

Here is the code I am using:
Private Sub nudNUMC_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles nudNUMC.KeyDown, nudNUMD.KeyDown

Dim nud As NumericUpDown = sender
'Allowed Keycodes:
' KeyCode 49 = 1 : KeyCode 97 = NumKey 1
' KeyCode 50 = 2 : KeyCode 98 = NumKey 2
' KeyCode 51 = 3 : KeyCode 99 = NumKey 3
' KeyCode 52 = 4 : KeyCode 100 = NumKey 4

If (e.KeyCode >= 49 And e.KeyCode <= 52) Or (e.KeyCode >= 97 And e.KeyCode <= 100) Then
Select Case e.KeyCode
Case 49, 97
nud.Value = 1
Case 50, 98
nud.Value = 2
Case 51, 99
nud.Value = 3
Case 52, 100
nud.Value = 4
End Select
nud.Update()
ElseIf e.KeyCode = 8 Or e.KeyCode = 37 Or e.KeyCode = 39 Or e.KeyCode = 46 Then
'Ok
' KeyCode 8 = Backspace
' KeyCode 37 = Left Arrow
' KeyCode 39 = Right Arrow
' KeyCode 46 = Delete
Else
e.Handled = True
e.SuppressKeyPress = True
End If
End Sub


I was able to create a new project, add two NumericUpDown boxes named nudNUMC and nudNUMD with their MIN set to 1 and MAX set to 4 to isolate this scenario.

Thank you for any help and advice, Chris.
AnswerRe: NumericUpDown displays too many digits while it has focus Pin
Dave Kreskowiak20-Mar-07 6:10
mveDave Kreskowiak20-Mar-07 6:10 
GeneralRe: NumericUpDown displays too many digits while it has focus Pin
ChrisDavidson20-Mar-07 8:32
ChrisDavidson20-Mar-07 8:32 
GeneralRe: NumericUpDown displays too many digits while it has focus Pin
Dave Kreskowiak20-Mar-07 8:44
mveDave Kreskowiak20-Mar-07 8:44 
QuestionHow different size font insert in a DataGridView cell Pin
Che YoungSoo20-Mar-07 5:06
Che YoungSoo20-Mar-07 5:06 
Questioncontrols Pin
WhiteGirl2320-Mar-07 4:55
WhiteGirl2320-Mar-07 4:55 
AnswerRe: controls Pin
Dave Kreskowiak20-Mar-07 6:18
mveDave Kreskowiak20-Mar-07 6:18 
QuestionProblem with controlbox Pin
dBrong20-Mar-07 4:42
dBrong20-Mar-07 4:42 
AnswerRe: Problem with controlbox Pin
Johan Hakkesteegt21-Mar-07 2:54
Johan Hakkesteegt21-Mar-07 2:54 
GeneralRe: Problem with controlbox Pin
dBrong22-Mar-07 11:27
dBrong22-Mar-07 11:27 
QuestionHow can I read a value from a XML file? Pin
JUNEYT20-Mar-07 3:27
JUNEYT20-Mar-07 3:27 
AnswerRe: How can I read a value from a XML file? Pin
Dave Kreskowiak20-Mar-07 4:53
mveDave Kreskowiak20-Mar-07 4:53 
GeneralRe: How can I read a value from a XML file? Pin
JUNEYT20-Mar-07 9:22
JUNEYT20-Mar-07 9:22 
QuestionUse a Web Control in VB.NET Pin
ayeleteric20-Mar-07 3:06
ayeleteric20-Mar-07 3:06 
AnswerRe: Use a Web Control in VB.NET Pin
Dave Kreskowiak20-Mar-07 4:42
mveDave Kreskowiak20-Mar-07 4:42 
GeneralRe: Use a Web Control in VB.NET Pin
ayeleteric20-Mar-07 4:45
ayeleteric20-Mar-07 4:45 
GeneralRe: Use a Web Control in VB.NET Pin
Dave Kreskowiak20-Mar-07 5:00
mveDave Kreskowiak20-Mar-07 5:00 
GeneralRe: Use a Web Control in VB.NET Pin
ayeleteric20-Mar-07 5:02
ayeleteric20-Mar-07 5:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.