zoukankan      html  css  js  c++  java
  • VB开发——自定义控件源码

    源代码如下:

    Option Explicit
    '自定义文本框输入控件
    '检测用户输入是否为数值

    Private Sub Text1_Change()
        If IsNumeric(Text1.text) = False And Trim(Text1.text) <> "-" And Trim(Text1.text) <> "" Then
            MsgBox "输入中含有非法字符!", 16, ""
            Text1.SetFocus
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.text)
        End If
    End Sub

    Private Sub Text1_KeyPress(KeyAscii As Integer)
        Dim str As String
        str = Trim(Text1.text)

        Select Case KeyAscii
        Case 8, 9, 13, &H30 To &H39
            KeyAscii = KeyAscii

        Case 45             '负号[只充许字符的第一个字符是负号]
            If str = "" Then
                KeyAscii = KeyAscii
            Else
                KeyAscii = 0
            End If
       
        Case 46             '小数点处理[前面字符中没有小数点则可以输入]
            If (IsNumeric(str) = True And InStr(1, str, ".") = 0) Or str = "" Then
                KeyAscii = KeyAscii
            Else
                KeyAscii = 0
            End If
           
        Case Else
            KeyAscii = 0
        End Select
    End Sub

    Private Sub Text1_LostFocus()
        If IsNumeric(Text1.text) = False And Trim(Text1.text) <> "" Then
            MsgBox "输入中含有非法字符!", 16, ""
            Text1.SetFocus
            Text1.SelStart = 0
            Text1.SelLength = Len(Text1.text)
        End If
    End Sub

    'text属性
    Public Property Get text() As String
        text = Text1.text
    End Property

    Public Property Let text(str1 As String)
        Text1.text = str1
        PropertyChanged "text"
    End Property

    '文本框高度
    Public Property Get txtheight() As Integer
        txtheight = Text1.height
    End Property

    Public Property Let txtheight(iheight As Integer)
        Text1.height = iheight
    End Property

    'width
    '文本框宽度
    Public Property Get txtwidth() As Integer
        txtwidth = Text1.Width
    End Property

    Public Property Let txtwidth(iwidth As Integer)
        Text1.Width = iwidth
    End Property

    '字体
    Public Property Get fontsize() As Integer
        fontsize = Text1.fontsize
    End Property

    Public Property Let fontsize(isize As Integer)
        Text1.fontsize = isize
    End Property

    P:

    怎样写自定义控件的?~就是像你上面的源码~~怎样转成控件的?~~请指教~~
    -----------------------------------
    是这样的,新建一个用户控件,[注意不是建一个窗体,看好选项.]
    然后在上面放一个文本框.然后将我的代码全面复制到代码栏中就可以了.
    然后在工具箱中就会出现这个自定义控件了.

  • 相关阅读:
    我的第一篇博客缓存显示图片
    CSLA.Net 学习 WCF服务端与客户端配置
    CSLA.Net 学习 刚接触
    [转] DevExpress 第三方控件汉化的全部代码和使用方法
    java版飞信协议实现
    [转]C#反射技术之一读取和设置类的属性
    NHibernate帮助类
    Oracle 11g 精简客户端打包 201206更新
    Mygeneration模板(NHibernate)生成,根据kdup的修改而来
    [转]TransactionScope应用
  • 原文地址:https://www.cnblogs.com/ainima/p/6331577.html
Copyright © 2011-2022 走看看