vb.net中的类差异非常有用的功能 [英] class diffrent very usefull function in vb.net

查看:106
本文介绍了vb.net中的类差异非常有用的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好:)
我在Vb.net编程中是PingLocalHostand我是新手,在创建系统时我不知道如何使用类.我喜欢在vb.net中练习面向对象. .
谁能给出一些与我的主要形式有关的有用的示例代码或函数.并可以在表单中用作我的文本框等的验证,因为我有点困惑. . .谢谢:)

Hello:)
Im PingLocalHostand im newbie in vb.net Programming and i dont know how to use a Class when i create a System. i like to practice a Object Oriented in vb.net . .
can any one give a some usefull sample code or function that conect to my main form . and can use as Validation for my textbox etc in my form because im a little bit Confusing . . . Thank All :)

推荐答案

有多种方法可以验证文本框中的数据-您可以使用输入掩码将输入限制为某些字符,正则表达式,调用文本更改等功能...

Google vb.net文本框验证,您将获得一串代码示例...
There are many different ways to validate data in your textbox - you can use an input mask to restrict entry to certain characters, a regular expression, call a function on text changed etc...

Google vb.net textbox validation and you will have a squillion code samples...


向您的项目添加类
命名为myCon或其他名称
假设您的主要表单名称是Form1
在其上放置两个文本框
textBox1和textBox2
textBox1必须只接受字母
textBox2必须仅接受数字
在您的课程上添加以下代码:
Add a Class To your Project
name it myCon or Whatever
Assume that your main form name is Form1
Place Two TextBoxes on it
textBox1 and textBox2
textBox1 must only accept Alphabets
textBox2 must only accept Numbers
add the following Code On your Class :
Public Sub txtValidation(ByVal e)
        If (Asc(e.KeyChar)) < 65 Or (Asc(e.KeyChar)) > 90 And (Asc(e.KeyChar)) < 97 Or (Asc(e.KeyChar)) > 122 Then

            If (Asc(e.KeyChar) <> 32) Then
                e.Handled = True
            End If
        End If
        If (Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub


上面的代码将限制用户输入
除字母外的任何其他文本.仅用于数字,然后将以下内容添加到您的班级中:


the above Code will Restrict The user to input
any other text except alphabets.Next for Numbers only, add the Following to your Class:

Public Sub txtNumberValidation(ByVal e)
        If (Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
            e.Handled = True

        End If
        If (Asc(e.KeyChar) = 8) Then
            e.Handled = False
        End If
    End Sub


之后,添加一个模块,为其命名,并创建您的Class对象.在此处向模块声明以下代码,以便您可以在项目中的任何位置访问它:


After that Add a module,name it whatever and to create the object of your Class.Declare here the following Code to your module,so that you can access it anywhere in your project :

Public valid As myCon


最后,进入包含文本框的主窗体
然后在事件上输入以下代码来调用类和验证函数


And Finally move on to your main form Containing Textboxes
and on there keypress Event put the following Code to call the Class and the Function for the Validation

Private Sub textBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox1.KeyPress
        valid = New myCon
        valid.txtValidation(e)


    End Sub

 Private Sub textBox2_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textBox2.KeyPress

        valid = New myCon
        valid.txtNumberValidation(e)
       
    End Sub


全部运行,学习.这些东西与OOPS有关.有关更多信息,请单击此处[ ^ ]好玩.


That''s all Run it ,learn it. These things are something about OOPS.for more Info Click here[^] Have Fun..


这篇关于vb.net中的类差异非常有用的功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆