Click here to Skip to main content
16,007,504 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionChange TimeZone of Windows Pin
azmayullah17-Jan-08 3:49
azmayullah17-Jan-08 3:49 
QuestionHas this command been removed? Pin
Richard Jones17-Jan-08 2:09
Richard Jones17-Jan-08 2:09 
AnswerRe: Has this command been removed? Pin
Richard Jones17-Jan-08 2:17
Richard Jones17-Jan-08 2:17 
QuestionHow can I display a web page on a windows form Pin
SekharOne17-Jan-08 1:01
SekharOne17-Jan-08 1:01 
AnswerRe: How can I display a web page on a windows form Pin
Steven J Jowett17-Jan-08 1:31
Steven J Jowett17-Jan-08 1:31 
GeneralRe: How can I display a web page on a windows form Pin
SekharOne17-Jan-08 23:01
SekharOne17-Jan-08 23:01 
QuestionNumeric TextBox In VB.Net 2005 Pin
ejaz_pk16-Jan-08 23:01
ejaz_pk16-Jan-08 23:01 
GeneralRe: Numeric TextBox In VB.Net 2005 Pin
Steven J Jowett17-Jan-08 1:25
Steven J Jowett17-Jan-08 1:25 
Create a new class called NumericBox and inherit Windows.Forms.TextBox

Now all you need to do is intercept keypresses with the KeyPress event, and validate them, for example :-

Private Sub NumericBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress<br />
        Dim KeyAscii As Integer<br />
<br />
        KeyAscii = Asc(e.KeyChar)<br />
<br />
        Select Case KeyAscii<br />
            Case 8, 13 ' backspace and carriage return<br />
                'Do nothing as the input is valid<br />
            Case 48 To 57 ' Keys 0 to 9 <br />
                'Test the number of decimal places<br />
                If Me.Text.Contains(".") Then<br />
                    If (Me.Text.Trim.Length - InStr(Me.Text, ".")) >= DecimalPlaces Then KeyAscii = 0<br />
                End If<br />
<br />
                'Test to see if the new value will exceed the maximum value<br />
                'or minimum value limits<br />
                Dim sValue As String = Value.ToString<br />
                Dim dValue As String<br />
                sValue &= e.KeyChar<br />
                dValue = CType(sValue, Decimal)<br />
                If dValue < Minimum Or dValue > Maximum Then KeyAscii = 0<br />
<br />
                'Do nothing as the input is valid<br />
            Case 45 'minus sign<br />
                If AllowNegativeValues Then<br />
                    'If negative values as permitted then...<br />
                    If Me.Text.Contains("-") Then<br />
                        'if we already have a minus sign then throw away this minus sign keystroke just pressed<br />
                        KeyAscii = 0<br />
                    End If<br />
<br />
                    If Me.SelectionStart <> 0 Then<br />
                        'If the insertion point is not sitting at zero (the beginning of the field),<br />
                        'throw away the minus sign<br />
                        KeyAscii = 0<br />
                    End If<br />
                Else<br />
                    KeyAscii = 0<br />
                End If<br />
<br />
            Case 46 'decimal point<br />
                If AllowDecimalPoint Then<br />
                    If Me.Text.Contains(".") Then<br />
                        KeyAscii = 0<br />
                    End If<br />
                Else<br />
                    KeyAscii = 0<br />
                End If<br />
<br />
            Case Else<br />
                'Any other input is invalid so throw it away<br />
                KeyAscii = 0<br />
        End Select<br />
<br />
        If KeyAscii = 0 Then<br />
            Beep()<br />
            e.Handled = True<br />
        Else<br />
            e.Handled = False<br />
        End If<br />
<br />
    End Sub


The snippet above utilises additional properties I have added to my NumericBox, should as AllowNegativeValues and AllowDecimalPoints both of which are Boolean values

Steve Jowett
-------------------------
Sometimes a man who deserves to be looked down upon because he is a fool, is only despised only because he is an 'I.T. Consultant'

GeneralRe: Numeric TextBox In VB.Net 2005 Pin
Dave Doknjas17-Jan-08 14:02
Dave Doknjas17-Jan-08 14:02 
GeneralRe: Numeric TextBox In VB.Net 2005 Pin
jamilkhan00717-Jan-08 20:02
jamilkhan00717-Jan-08 20:02 
QuestionHow to implement Cut,Copy,Paste for controls in vb.net 2005 Pin
for120616-Jan-08 22:44
for120616-Jan-08 22:44 
GeneralEmail sending in VB.NET Pin
plural16-Jan-08 21:17
plural16-Jan-08 21:17 
GeneralRe: Email sending in VB.NET Pin
Jats_4ru16-Jan-08 21:57
Jats_4ru16-Jan-08 21:57 
GeneralRe: Email sending in VB.NET Pin
plural16-Jan-08 22:36
plural16-Jan-08 22:36 
AnswerRe: Email sending in VB.NET Pin
Steven J Jowett17-Jan-08 0:50
Steven J Jowett17-Jan-08 0:50 
GeneralRe: Email sending in VB.NET Pin
Jats_4ru17-Jan-08 23:24
Jats_4ru17-Jan-08 23:24 
QuestionHow do you save a picture from a web site? Pin
Reveille16-Jan-08 20:48
Reveille16-Jan-08 20:48 
GeneralPlease help me with job scheduling in SQL Server 2005... Pin
Support12316-Jan-08 20:42
Support12316-Jan-08 20:42 
QuestionRe: Please help me with job scheduling in SQL Server 2005... Pin
Steven J Jowett17-Jan-08 1:10
Steven J Jowett17-Jan-08 1:10 
GeneralRe: Please help me with job scheduling in SQL Server 2005... Pin
Support12317-Jan-08 2:41
Support12317-Jan-08 2:41 
GeneralREGEX VS ARRAYLIST.BINARYSEARCH Pin
balakpn16-Jan-08 19:34
balakpn16-Jan-08 19:34 
GeneralSchhhhh! Pin
Guffa17-Jan-08 9:03
Guffa17-Jan-08 9:03 
Generalwant to create Auto Hide window Pin
phoopwint16-Jan-08 17:18
phoopwint16-Jan-08 17:18 
GeneralRe: want to create Auto Hide window Pin
Nilesh Hapse16-Jan-08 17:27
Nilesh Hapse16-Jan-08 17:27 
GeneralRelease/Renew IP app Pin
Aptiva Dave16-Jan-08 16:44
Aptiva Dave16-Jan-08 16:44 

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.