做了一个文本框控件,可是拖到窗体上时,可以设置自定义属性,当时可以反映,可是保存不了.下次打开时又是这个控件设计时的大小了.
-----------------
比如在窗体上设置高和宽的属性.可以在窗体上反映出来.但是无法保存,下次打开窗体时又恢复到控件设计时的大小了.请问我的控件设计代码错在哪里.下面是代码,请教大家.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
解决方案 »
- 有没有这样的做法?关于编程思路
- 请教各位大侠 们 TDBGrid 的一些用法
- 如何把foxpro数据库转成access的?我代码哪错啦?
- 100分求救对mscomm控件通信发送16进制接收16进制数据的代码,谢谢!
- 网页图片提取的问题?????
- 请教高手:如何通过程序来识别不同的软盘?
- 如何取得非本工程的窗体句柄
- 88分==>>定时运行的问题。
- 救急!·救急!!高手请赐教!!在vb 中如何调用系统发音函数呢
- vb能向flash传变量吗?怎么传?
- 正常字符串加密后结果如下,如何将他保存到数据库中(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