做了一个文本框控件,可是拖到窗体上时,可以设置自定义属性,当时可以反映,可是保存不了.下次打开时又是这个控件设计时的大小了.
-----------------
比如在窗体上设置高和宽的属性.可以在窗体上反映出来.但是无法保存,下次打开窗体时又恢复到控件设计时的大小了.请问我的控件设计代码错在哪里.下面是代码,请教大家.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 SubPrivate 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 SubPrivate 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 PropertyPublic Property Let text(str1 As String)
Text1.text = str1
PropertyChanged "text"
End Property'文本框高度
Public Property Get txtheight() As Integer
txtheight = Text1.height
End PropertyPublic Property Let txtheight(iheight As Integer)
Text1.height = iheight
End Property'width
'文本框宽度
Public Property Get txtwidth() As Integer
txtwidth = Text1.Width
End PropertyPublic Property Let txtwidth(iwidth As Integer)
Text1.Width = iwidth
End Property'字体
Public Property Get fontsize() As Integer
fontsize = Text1.fontsize
End PropertyPublic Property Let fontsize(isize As Integer)
Text1.fontsize = isize
End Property
-----------------
比如在窗体上设置高和宽的属性.可以在窗体上反映出来.但是无法保存,下次打开窗体时又恢复到控件设计时的大小了.请问我的控件设计代码错在哪里.下面是代码,请教大家.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 SubPrivate 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 SubPrivate 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 PropertyPublic Property Let text(str1 As String)
Text1.text = str1
PropertyChanged "text"
End Property'文本框高度
Public Property Get txtheight() As Integer
txtheight = Text1.height
End PropertyPublic Property Let txtheight(iheight As Integer)
Text1.height = iheight
End Property'width
'文本框宽度
Public Property Get txtwidth() As Integer
txtwidth = Text1.Width
End PropertyPublic Property Let txtwidth(iwidth As Integer)
Text1.Width = iwidth
End Property'字体
Public Property Get fontsize() As Integer
fontsize = Text1.fontsize
End PropertyPublic Property Let fontsize(isize As Integer)
Text1.fontsize = isize
End Property
解决方案 »
- MDI动态子窗口的问题
- 如何用VB实现的图片滚动
- 在窗体中的每个按钮的事件中对数据操作完毕,都应该关闭连接吗?[后台是sql server,用ado记录集]
- 将DataGrid中的内容导入到Excel中出现的问题
- 在程式调用EXCEL后,如何正常关闭它?
- 如何读出Excel中插入的Jpb图片,保存成jpg或者bmp(100分),给点思路也行
- VB 的 ComboBox 怎样设置才能禁止用户编辑 Item, 但又可以让用户选择已有的 Item?
- datagrid控件中,怎样选择多个纪录?怎样将多个纪录删除?
- 关于用CLS清除图片框里内容
- 一个牵套循环的问题?
- 正常字符串加密后结果如下,如何将他保存到数据库中(Insert/Update)
- 分享我的自定义控件源码[作用是只能输入数值的文本框],初学者参考.高手多提意见.
Private Sub UserControl_ReadProperties(PropBag As PropertyBag) wskPLC.RemoteHost = PropBag.ReadProperty("RemoteHost", "")
m_ComMode = PropBag.ReadProperty("ComMode", m_def_ComMode)
m_RemoteHost = PropBag.ReadProperty("RemoteHost", m_def_RemoteHost)
m_Settings = PropBag.ReadProperty("Settings", m_def_Settings)
m_PortOpen = PropBag.ReadProperty("PortOpen", m_def_PortOpen)
m_Port = PropBag.ReadProperty("Port", m_def_Port)
m_SNA = PropBag.ReadProperty("SNA", m_def_SNA)
m_DNA = PropBag.ReadProperty("DNA", m_def_DNA)
m_DA1 = PropBag.ReadProperty("DA1", m_def_DA1)
m_BytesReceived = PropBag.ReadProperty("BytesReceived", m_def_BytesReceived)
m_CommandCode = PropBag.ReadProperty("CommandCode", m_def_CommandCode)
m_AddressCode = PropBag.ReadProperty("AddressCode", m_def_AddressCode)
m_Address = PropBag.ReadProperty("Address", m_def_Address)
m_MemorySize = PropBag.ReadProperty("MemorySize", m_def_MemorySize)
End Sub
'字体
Public Property Get fontsize() As Integer
fontsize = Text1.fontsize
End PropertyPublic Property Let fontsize(isize As Integer)
Text1.fontsize = isize
PropertyChanged “fontsize”
End Property'从存贮器中加载属性值
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Text1.fontsize=PropBag.ReadProperty("fontsize",15)'其中函数的第二个参数可以用一个常量来替代
End Sub
'将属性值写到存储器
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("fontsize", Text1.fontsize, 15)'其中函数的第二个参数可以用一个常量来替代 End Sub
'自定义文本框输入控件
'检测用户输入是否为数值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 SubPrivate 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 SubPrivate 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 PropertyPublic Property Let text(str1 As String)
Text1.text = str1
PropertyChanged "text"
End Property'文本框高度
Public Property Get txtheight() As Integer
txtheight = Text1.height
End PropertyPublic Property Let txtheight(iheight As Integer)
Text1.height = iheight
End Property'width
'文本框宽度
Public Property Get txtwidth() As Integer
txtwidth = Text1.Width
End PropertyPublic Property Let txtwidth(iwidth As Integer)
Text1.Width = iwidth
End Property'字体
Public Property Get fontsize() As Integer
fontsize = Text1.fontsize
End PropertyPublic Property Let fontsize(isize As Integer)
Text1.fontsize = isize
PropertyChanged "fontsize"
End Property
Private Sub UserControl_Initialize()
Text1.fontsize = 12
End SubPrivate Sub UserControl_ReadProperties(PropBag As PropertyBag)
Text1.fontsize = PropBag.ReadProperty("fontsize", 12) '其中函数的第二个参数可以用一个常量来替代
End SubPrivate Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("fontsize", Text1.fontsize, 18) '其中函数的第二个参数可以用一个常量来替代
End Sub