十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
继承button,然后增加事件
成都创新互联公司专注于普宁企业网站建设,成都响应式网站建设公司,成都做商城网站。普宁网站建设公司,为普宁等地区提供建站服务。全流程按需求定制制作,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务
并且自定义EventArg
思路:
class MyEventArg :EventArg
{
public long MyNum
{
set{ myNum = value;}
get{ return myNum; }
}
private long myNum ;
}
class MyButton:System.Windows.Forms.Button
{
public delegate void MyClick(object sender,MyEventArg e);
public event MyClick OnMyClick;
private MyEventArg myE = new MyEventarg();
protected override void OnClick(EventArgs e)
{
if(OnMyClick != null)
{
OnMyClick(null,myE);
}
base.OnClick(e);
}
}
变量值的改变本身就是你程序控制的,也就是说它的变化完全是在你掌控中的,做变量值改变的触发事件实在没有价值。
通常编程者关心的应该是用户操作的控件值发生变化,但这些控件的事件通常都是定义好的,且已经定义的非常全了。
猜测搂主其实是想学习自己制作控件,那就高深了,很多底层的事件通常都是从基本控件中获得的!
Imports System.Text
Imports System.Windows
Imports System.Windows.Forms
Public Class Netin '类 名
'Inherits Forms.Form
Public Shared Netin As New Form
Public components As ComponentModel.IContainer
Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub
DebuggerStepThrough()
Public Sub InitializeComponent()
Me点抗 ponents = New ComponentModel.Container()
Dim resources As ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(bjt))
Me.TextBox1 = New TextBox(Me点抗 ponents)
Me.Button1 = New Button(Me点抗 ponents)
'For … Next
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Button1)
Me.m = New ContextMenuStrip(Me点抗 ponents)
Me.m1.Text = "菜单项1"
'设置并添加相关控件,(窗体)Netin 初始化。
End Sub
Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
'加载后显示窗体Netin。
End Sub
Public Sub ObjClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click,Button2.Click,Button3.Click,TextBox1.Click
MessageBox.Show("你按了鼠标")
End Sub
Public WithEvents TextBox1 As TextBox
Public WithEvents Button1 As Button
Public WithEvents Button2 As Button
Public WithEvents Button3 As Button
Friend WithEvents m As ContextMenuStrip
Friend WithEvents m1 As ToolStripMenuItem
End Class
Class MainWindow
Netin.Show()
Netin.Button2.Text = "Main"
……
题外话,从JAVA转过来的,为什么不用C#,毕竟JAVA和C#接近
添加事件处理程序借助设计器就可以了.我下面说的是如何用代码处理
在用户控件的构造函数Sub New()里添加代码注册事件处理函数
AddHandler ToolStripMenuItem1.Click, AddressOf MyHandler
然后实现这个处理函数
Sub MyHandler(sender As Object, e As EventArgs)
'在这里处理这个菜单命令
End Sub