首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

TEXTBOX 用户控件,无法响应回车,大家帮小弟我看下

2012-02-22 
TEXTBOX 用户控件,无法响应回车,大家帮我看下Option ExplicitPrivate Sub UserControl_Initialize()UserCo

TEXTBOX 用户控件,无法响应回车,大家帮我看下
Option Explicit

Private Sub UserControl_Initialize()
UserControl.BackColor = 0
UserControl.ScaleMode = vbPixels
Text1.BorderStyle = 0
End Sub

Private Sub UserControl_Resize()
Text1.Move 1, 1, UserControl.ScaleWidth - 2, UserControl.ScaleHeight - 2
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Text1.Text = PropBag.ReadProperty("Text")
UserControl.BackColor = PropBag.ReadProperty("BorderColor")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Text", Text1.Text)
Call PropBag.WriteProperty("BorderColor", UserControl.BackColor)
End Sub

Public Property Get Text() As String
Text = Text1.Text
End Property
Public Property Let Text(ByVal New_Value As String)
Text1.Text = New_Value
UserControl.PropertyChanged "Text"
End Property

Public Property Get BorderColor() As OLE_COLOR
BorderColor = UserControl.BackColor
End Property
Public Property Let BorderColor(ByVal New_Value As OLE_COLOR)
UserControl.BackColor = New_Value
UserControl.PropertyChanged "BorderColor"
End Property

这上面是我自定义的用户控件

Private Sub text1_KeyPress(KeyAscii As Integer)
MsgBox "这里捕捉不到"
End Sub

为什么KeyPress这个属性在这就失效了呢?是不是在用户控件里还需要加入什么代码?

[解决办法]
其它键能捕获吗?
[解决办法]

探讨
Option Explicit

Private Sub UserControl_Initialize()
UserControl.BackColor = 0
UserControl.ScaleMode = vbPixels
Text1.BorderStyle = 0
End Sub

Private Sub UserControl_Resize()
Text1.Move 1, ……

[解决办法]
....
Public Property Let BorderColor(ByVal New_Value As OLE_COLOR)
UserControl.BackColor = New_Value
UserControl.PropertyChanged "BorderColor"
End Property
这上面是我自定义的用户控件

Private Sub text1_KeyPress(KeyAscii As Integer)
MsgBox "这里捕捉不到"
End Sub


你的代码看起来没问题,你用“这上面是我自定义的用户控件”分开,上面的代码不是写在一个模块中?
[解决办法]
引用 1 楼 :
Private Sub text1_KeyPress(KeyAscii As Integer)
MsgBox "这里捕捉不到"
End Sub

[解决办法]

呵呵。。。笨蛋。。。。

热点排行