怎么会捏,你是不是没有加上mybase.keypress
站在用户的角度思考问题,与客户深入沟通,找到新蔡网站设计与新蔡网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站设计、网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、网页空间、企业邮箱。业务覆盖新蔡地区。
正确的重写步骤:新建一个Component-类下面一行写上Inherits
TextBox-然后写入:
Protected
Overrides
Sub
OnKeyPress(ByVal
e
As
System.Windows.Forms.KeyPressEventArgs)
MyBase.OnKeyPress(e)'这个东东是原来的keypress执行的代码,它会引发keypress事件
'-----这里写代码
End
Sub
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim a As New month(1)
MessageBox.Show(a.ToString)
End Sub
End Class
Public Class month
Dim m As Integer
Public Sub New(i As Integer)
m = i
End Sub
Public Overrides Function ToString() As String
If m = 1 And m = 12 Then
Return Choose(m, "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二") + "月"
Else
Return m.ToString
End If
End Function
End Class
'把图片的声明放在外面,类里面过程外面,而且要用As,不然等会儿没法用
Dim myPicture As New System.Windows.Forms.PictureBox()
'动态生成的控件,加一行
Private Sub UserControl1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Panel3.Controls.Add(myPicture)
myPicture.Size =New System.Drawing.Size(115, 160)
myPicture.TabStop =False
myPicture.Name ="p"
myPicture.Cursor = Cursors.Hand
AddHandler myPicture.Click, AddressOf mypic_Click '添加事件
AddHandler returnid, AddressOf idReturned '绑定事件和过程
End Sub
'再来个事件,放在声明的地方,就是类里面、过程外面
Private Event returnid(ByVal id As String) '这个事件可以传递值哦~
'普通的单击事件
Private Sub mypic_Click()
RaiseEvent returnid(myPicture.Name)
End Sub
'会传值的事件过程
Private Sub idReturned(ByVal id As String)
Dim bookInfo As New BookInfo
bookInfo.Show()
Me.Parent.Enabled = False
'用id变量做点什么吧
End Sub
如果要改事件的签名(参数一类的)的话,得重写控件。你可以这样自己弄一个事件。
某些键,如 Tab、Return、Esc 和箭头键,由控件自动处理。所以当你的窗体添加了其它控件如按钮,checkbox等,form的keydown事件就触发不了,为使这些键引发窗体的KeyDown事件,你需要重写form.ProcessDialogKey函数,这个函数可以在消息预处理期间 处理对话字符,例如TAB、RETURN、ESCAPE和箭头键等,以下是我重写了这个事件来处理方向键,你需要把它放到你的代码里:
Protected Overrides Function ProcessDialogKey(ByVal keyData As Keys) As Boolean
If keyData = Keys.Left Or keyData = Keys.Right Or keyData = Keys.Up Or keyData = Keys.Down Then
Return False'如果是方向键返回FALSE,意思是继续执行form的keydown事件.
Else
Return MyBase.ProcessDialogKey(keyData)
End If
End Function
售后响应及时
7×24小时客服热线数据备份
更安全、更高效、更稳定价格公道精准
项目经理精准报价不弄虚作假合作无风险
重合同讲信誉,无效全额退款