thebluesfc
Meme Archivist
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
500 XP
Today, I will teach you how to create a program that will disable paste in a numeric textbox using vb.net.
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Add only a TextBox named TextBoxNumeric in your Form.
3. Now, we will do the coding.
We will make first to disable paste in the textbox by creating a sub procedure named ReadOnlyText(ByVal TxtBox As TextBox, Optional ByVal LockTextBox As Boolean = True).
After creating the sub procedure, to totally disable the paste in the textbox, we will code for the MouseDown event of our textbox.
Then, after disabling paste, we will validate the textbox using the keypress event of our textbox.
Output:
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
Now, let's start this tutorial!
1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio: Go to File, click New Project, and choose Windows Application.
2. Add only a TextBox named TextBoxNumeric in your Form.
3. Now, we will do the coding.
We will make first to disable paste in the textbox by creating a sub procedure named ReadOnlyText(ByVal TxtBox As TextBox, Optional ByVal LockTextBox As Boolean = True).
- 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
After creating the sub procedure, to totally disable the paste in the textbox, we will code for the MouseDown event of our textbox.
- Private
Sub
TextBoxNumeric_MouseDown(
ByVal
sender As
Object
, ByVal
e As
System.
Windows
.
Forms
.
MouseEventArgs
)
Handles
TextBoxNumeric.
MouseDown
- ReadOnlyText(
TextBoxNumeric)
- End
Sub
Then, after disabling paste, we will validate the textbox using the keypress event of our textbox.
- Private
Sub
TextBoxNumeric_KeyPress(
ByVal
sender As
Object
, ByVal
e As
System.
Windows
.
Forms
.
KeyPressEventArgs
)
Handles
TextBoxNumeric.
KeyPress
- Dim
num As
Char
=
e.
KeyChar
- If
Char
.
IsDigit
(
num)
Or
num =
ChrW
(
Keys.
Back
)
Then
- ReadOnlyText(
TextBoxNumeric, False
)
- e.
Handled
=
False
- Else
- If
TextBoxNumeric.
Text
.
Contains
(
"."
)
=
True
Then
- e.
Handled
=
True
- Else
- If
num =
Char
.
Parse
(
"."
)
Then
- ReadOnlyText(
TextBoxNumeric, False
)
- e.
Handled
=
False
- Else
- e.
Handled
=
True
- End
If
- End
If
- End
If
- End
Sub
Output:

For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Best Regards,
Engr. Lyndon R. Bermoy
IT Instructor/System Developer/Android Developer
Mobile: 09079373999
Telephone: 826-9296
E-mail:[email protected]
Visit and like my page on Facebook at: Bermz ISware Solutions
Subscribe at my YouTube Channel at: SerBermz
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
You must upgrade your account or reply in the thread to view hidden text.