| | |
Related To Textbox
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
VB.NET Syntax (Toggle Plain Text)
Private Sub textBox_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox.KeyPress If Char.IsNumber(e.KeyChar) Or Asc(e.KeyChar) = 8 Then e.Handled = False Else e.Handled = True MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error") End If End Sub
basicly the IsNumber is numbers 0-9, it also allows the delete button, and the ASCII key 8 is the back space key
This following code just allowed you to entered numbers only (No alphabetics or any special characters) :
vb.net Syntax (Toggle Plain Text)
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) _ Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then e.Handled = True End If If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then e.Handled = False End If End Sub
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
well that is what you asked for
use google
try that, the e.Handled = False/True determins wether the charater is to be imputted - so just simply remove it
use google
VB.NET Syntax (Toggle Plain Text)
If Char.IsNumber(e.KeyChar)Then Else MsgBox("Numeric Values Only", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Input Error") End If
try that, the e.Handled = False/True determins wether the charater is to be imputted - so just simply remove it
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
Sorry that function is like this
Shared Sub SetTextboxAllowedCharacters(ByVal CharactersAllowed As String, ByRef e As System.Windows.Forms.KeyPressEventArgs, Optional ByVal enter As Boolean = True, Optional ByVal BackSpace As Boolean = True)
thanks
Shared Sub SetTextboxAllowedCharacters(ByVal CharactersAllowed As String, ByRef e As System.Windows.Forms.KeyPressEventArgs, Optional ByVal enter As Boolean = True, Optional ByVal BackSpace As Boolean = True)
VB.NET Syntax (Toggle Plain Text)
Dim err As Integer = 0 If InStr(CharactersAllowed, e.KeyChar.ToString.ToUpper) = 0 Then err = 1 If enter And Asc(e.KeyChar) = Keys.Enter Then err = 0 If BackSpace And Asc(e.KeyChar) = Keys.Back Then err = 0 If Asc(e.KeyChar) = 3 Then err = 0 If Asc(e.KeyChar) = 22 Then err = 0 End If If err = 1 Then e.Handled = True End If End Sub
Last edited by Ancient Dragon; Jan 28th, 2009 at 7:52 pm. Reason: add code tags
![]() |
Similar Threads
- query related to gridview (VB.NET)
- C#,Asp.net in vs 2008 related to modal popup extender (ASP.NET)
- Few Questions: textBox, checkBox/Form Related (C#)
- sending textbox info from one page to another (JSP)
- How can define custom events,properties (C#)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
- Populating & Retrieving Data in a listbox : ASP.NET (w/ VB.NET) (ASP.NET)
- No Posts? (DaniWeb Community Feedback)
- Dividing up the site (DaniWeb Community Feedback)
Other Threads in the VB.NET Forum
- Previous Thread: How To Add Multiple Rows In A Datatable
- Next Thread: how to make execution file in microsoft visual studio
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component crystalreport data database datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project read remove save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year






