بسم الله الرحمن الرحيم
[SIZE=4]الحمد لله وحده والصلاة والسلام على من لا نبي بعدهوبعد
[/SIZE]السلام عليكم ورحمة الله وبركاته
هذا الكود البسيط وظيفته أنه يجعل أداة النص لا تقبل إلا الأرقام فقط
مع ملاحظة صغيرة أنه يدعم اختصارات النسخ والقص واللصق شريطة أن يكون المراد لصقه رقما أيضا
وإليكم الكود
كود :
Private FunctionCopyPasteCut As Boolean = False
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
Select Case e.KeyData
Case 131158
' "Paste"
If IsNumeric(Clipboard.GetText) Then FunctionCopyPasteCut = True
Case 131160
' "Cut"
FunctionCopyPasteCut = True
Case 131139
' "Copy"
FunctionCopyPasteCut = True
End Select
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If FunctionCopyPasteCut = True Then
FunctionCopyPasteCut = False
Exit Sub
End If
If Not IsNumeric(e.KeyChar) Then
If Not Asc(e.KeyChar) = Keys.Back Then
e.Handled = True
End If
End If
End Sub