Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Disable [ Paste ] for Numeric Textbox
Author:
Gehan Fernando
E-mail:
Click to e-mail author
Submitted:
3/16/2011
Version:
VB 2008
Compatibility:
VB 2008, VB 2010
Category:
Controls
Views:
9136
Disable [ Paste ] for numeric textbox.
Declarations:
'none
Code:
Imports System Imports System.Drawing Public Class Form1 Private Sub TextBoxNumeric_KeyPress(ByVal sender As System.Object, ByVal e As KeyPressEventArgs) Handles TextBoxNumeric.KeyPress Dim digit As Char = e.KeyChar If Char.IsDigit(digit) Or digit = ChrW(Keys.Back) Then ReadOnlyText(TextBoxNumeric, False) e.Handled = False Else If TextBoxNumeric.Text.Contains(".") = True Then e.Handled = True Else If digit = Char.Parse(".") Then ReadOnlyText(TextBoxNumeric, False) e.Handled = False Else e.Handled = True End If End If End If End Sub Private Sub ReadOnlyText(ByVal TxtBox As TextBox, Optional ByVal LockTextBox As Boolean = True) Dim Clr As Color = TxtBox.BackColor TxtBox.ReadOnly = LockTextBox TxtBox.BackColor = Clr End Sub Private Sub TextBoxNumeric_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBoxNumeric.MouseDown ReadOnlyText(TextBoxNumeric) End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement