135-1821-9792

关于vb点虐 事件说明的信息

vb点虐 中如何用事件和委托,会C#中的事件和委托,但不知VB点虐 中的语法,望给个简单的例子熟悉语法。

一委托:此示例演示如何将方法与委托关联然后通过委托调用该方法。

江夏ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

创建委托和匹配过程

创建一个名为 MySubDelegate 的委托。

Delegate Sub MySubDelegate(ByVal x As Integer)

声明一个类,该类包含与该委托具有相同签名的方法。

Class class1

Sub Sub1(ByVal x As Integer)

MsgBox("The value of x is: " CStr(x))

End Sub

End Class

定义一个方法,该方法创建该委托的实例并通过调用内置的 Invoke 方法调用与该委托关联的方法。

Protected Sub DelegateTest()

Dim c1 As New class1

' Create an instance of the delegate.

Dim msd As MySubDelegate = AddressOf c1.Sub1

' Call the method.

msd.Invoke(10)

End Sub

二、事件

下面的示例程序阐释如何在一个类中引发一个事件,然后在另一个类中处理该事件。AlarmClock 类定义公共事件 Alarm,并提供引发该事件的方法。AlarmEventArgs 类派生自 EventArgs,并定义 Alarm 事件特定的数据。WakeMeUp 类定义处理 Alarm 事件的 AlarmRang 方法。AlarmDriver 类一起使用类,将使用 WakeMeUp 的 AlarmRang 方法设置为处理 AlarmClock 的 Alarm 事件。

该示例程序使用事件和委托和引发事件中详细说明的概念。

示例

' EventSample.vb.

'

Option Explicit

Option Strict

Imports System

Imports System.ComponentModel

Imports Microsoft.VisualBasic

Namespace EventSample

' Class that contains the data for

' the alarm event. Derives from System.EventArgs.

'

Public Class AlarmEventArgs

Inherits EventArgs

Private _snoozePressed As Boolean

Private nrings As Integer

'Constructor.

'

Public Sub New(snoozePressed As Boolean, nrings As Integer)

Me._snoozePressed = snoozePressed

Me.nrings = nrings

End Sub

' The NumRings property returns the number of rings

' that the alarm clock has sounded when the alarm event

' is generated.

'

Public ReadOnly Property NumRings() As Integer

Get

Return nrings

End Get

End Property

' The SnoozePressed property indicates whether the snooze

' button is pressed on the alarm when the alarm event is generated.

'

Public ReadOnly Property SnoozePressed() As Boolean

Get

Return _snoozePressed

End Get

End Property

' The AlarmText property that contains the wake-up message.

'

Public ReadOnly Property AlarmText() As String

Get

If _snoozePressed Then

Return "Wake Up!!! Snooze time is over."

Else

Return "Wake Up!"

End If

End Get

End Property

End Class

' Delegate declaration.

'

Public Delegate Sub AlarmEventHandler(sender As Object, _

e As AlarmEventArgs)

' The Alarm class that raises the alarm event.

'

Public Class AlarmClock

Private _snoozePressed As Boolean = False

Private nrings As Integer = 0

Private stopFlag As Boolean = False

' The Stop property indicates whether the

' alarm should be turned off.

'

Public Property [Stop]() As Boolean

Get

Return stopFlag

End Get

Set

stopFlag = value

End Set

End Property

' The SnoozePressed property indicates whether the snooze

' button is pressed on the alarm when the alarm event is generated.

'

Public Property SnoozePressed() As Boolean

Get

Return _snoozePressed

End Get

Set

_snoozePressed = value

End Set

End Property

' The event member that is of type AlarmEventHandler.

'

Public Event Alarm As AlarmEventHandler

' The protected OnAlarm method raises the event by invoking

' the delegates. The sender is always this, the current instance

' of the class.

'

Protected Overridable Sub OnAlarm(e As AlarmEventArgs)

RaiseEvent Alarm(Me, e)

End Sub

' This alarm clock does not have

' a user interface.

' To simulate the alarm mechanism it has a loop

' that raises the alarm event at every iteration

' with a time delay of 300 milliseconds,

' if snooze is not pressed. If snooze is pressed,

' the time delay is 1000 milliseconds.

'

Public Sub Start()

Do

nrings += 1

If stopFlag Then

Exit Do

Else

If _snoozePressed Then

System.Threading.Thread.Sleep(1000)

If (True) Then

Dim e As New AlarmEventArgs(_snoozePressed, nrings)

OnAlarm(e)

End If

Else

System.Threading.Thread.Sleep(300)

Dim e As New AlarmEventArgs(_snoozePressed, nrings)

OnAlarm(e)

End If

End If

Loop

End Sub

End Class

' The WakeMeUp class has a method AlarmRang that handles the

' alarm event.

'

Public Class WakeMeUp

Public Sub AlarmRang(sender As Object, e As AlarmEventArgs)

Console.WriteLine((e.AlarmText + ControlChars.Cr))

If Not e.SnoozePressed Then

If e.NumRings Mod 10 = 0 Then

Console.WriteLine(" Let alarm ring? Enter Y")

Console.WriteLine(" Press Snooze? Enter N")

Console.WriteLine(" Stop Alarm? Enter Q")

Dim input As String = Console.ReadLine()

If input.Equals("Y") Or input.Equals("y") Then

Return

Else

If input.Equals("N") Or input.Equals("n") Then

CType(sender, AlarmClock).SnoozePressed = True

Return

Else

CType(sender, AlarmClock).Stop = True

Return

End If

End If

End If

Else

Console.WriteLine(" Let alarm ring? Enter Y")

Console.WriteLine(" Stop Alarm? Enter Q")

Dim input As String = Console.ReadLine()

If input.Equals("Y") Or input.Equals("y") Then

Return

Else

CType(sender, AlarmClock).Stop = True

Return

End If

End If

End Sub

End Class

' The driver class that hooks up the event handling method of

' WakeMeUp to the alarm event of an Alarm object using a delegate.

' In a forms-based application, the driver class is the

' form.

'

Public Class AlarmDriver

Public Shared Sub Main()

' Instantiates the event receiver.

Dim w As New WakeMeUp()

' Instantiates the event source.

Dim clock As New AlarmClock()

' Wires the AlarmRang method to the Alarm event.

AddHandler clock.Alarm, AddressOf w.AlarmRang

clock.Start()

End Sub

End Class

End Namespace

vb点虐 :声明事件和引用事件分别用的什么语句

声明事件只需用

private event 事件名称(参数表)

在通用部分声明

引用这个词不太恰当,应该说是触发

在需要触发的地方用

raiseevent 事件名称(参数表)就可以了

VB.NET的Form的所有事件

名称

说明

Activated

当使用代码激活或用户激活窗体时发生。

AutoSizeChanged

当 AutoSize 属性更改时发生。

AutoValidateChanged

当 AutoValidate 属性更改时发生。

BackColorChanged

当 BackColor 属性的值更改时发生。(从 Control 继承。)

BackgroundImageChanged

当 BackgroundImage 属性的值更改时发生。(从 Control 继承。)

BackgroundImageLayoutChanged

当 BackgroundImageLayout 属性更改时发生。(从 Control 继承。)

BindingContextChanged

当 BindingContext 属性的值更改时发生。(从 Control 继承。)

CausesValidationChanged

当 CausesValidation 属性的值更改时发生。(从 Control 继承。)

ChangeUICues

焦点或键盘用户界面 (UI) 提示更改时发生。(从 Control 继承。)

Click

在单击控件时发生。(从 Control 继承。)

ClientSizeChanged

当 ClientSize 属性的值更改时发生。(从 Control 继承。)

Closed

关闭窗体时发生。

Closing

关闭窗体时发生。

ContextMenuChanged

当 ContextMenu 属性的值更改时发生。(从 Control 继承。)

ContextMenuStripChanged

当 ContextMenuStrip 属性的值更改时发生。(从 Control 继承。)

ControlAdded

在将新控件添加到 Control.ControlCollection 时发生。(从 Control 继承。)

ControlRemoved

在从 Control.ControlCollection 移除控件时发生。(从 Control 继承。)

CursorChanged

当 Cursor 属性的值更改时发生。(从 Control 继承。)

Deactivate

当窗体失去焦点并不再是活动窗体时发生。

Disposed

当通过调用 Dispose 方法释放组件时发生。(从 Component 继承。)

DockChanged

当 Dock 属性的值更改时发生。(从 Control 继承。)

DoubleClick

在双击控件时发生。(从 Control 继承。)

DragDrop

拖放操作完成时发生。(从 Control 继承。)

DragEnter

在将对象拖入控件的边界时发生。(从 Control 继承。)

DragLeave

将对象拖出控件的边界时发生。(从 Control 继承。)

DragOver

在将对象拖到控件的边界上发生。(从 Control 继承。)

EnabledChanged

在 Enabled 属性值更改后发生。(从 Control 继承。)

Enter

进入控件时发生。(从 Control 继承。)

FontChanged

在 Font 属性值更改时发生。(从 Control 继承。)

ForeColorChanged

在 ForeColor 属性值更改时发生。(从 Control 继承。)

FormClosed

关闭窗体后发生。

FormClosing

关闭窗体前发生。

GiveFeedback

在执行拖动操作期间发生。(从 Control 继承。)

GotFocus

在控件接收焦点时发生。(从 Control 继承。)

HandleCreated

在为控件创建句柄时发生。(从 Control 继承。)

HandleDestroyed

在控件的句柄处于销毁过程中时发生。(从 Control 继承。)

HelpButtonClicked

单击“帮助”按钮时发生。

HelpRequested

用户请求控件帮助时发生。(从 Control 继承。)

ImeModeChanged

在 ImeMode 属性更改后发生。(从 Control 继承。)

InputLanguageChanged

更改窗体的输入语言后发生。

InputLanguageChanging

当用户尝试更改窗体的输入语言时发生。

Invalidated

控件的显示要求重新绘制时发生。(从 Control 继承。)

KeyDown

在控件有焦点的情况下按下键时发生。(从 Control 继承。)

KeyPress

在控件有焦点的情况下字符、空格或退格键时发生。(从 Control 继承。)

KeyUp

在控件有焦点的情况下释放键时发生。(从 Control 继承。)

Layout

在控件应重新定位其子控件时发生。(从 Control 继承。)

Leave

在输入焦点离开控件时发生。(从 Control 继承。)

Load

在第一次显示窗体前发生。

LocationChanged

在 Location 属性值更改后发生。(从 Control 继承。)

LostFocus

在控件失去焦点时发生。(从 Control 继承。)

MarginChanged

当 Margin 属性更改时发生。

MaximizedBoundsChanged

在 MaximizedBounds 属性的值更改后发生。

MaximumSizeChanged

在 MaximumSize 属性的值更改后发生。

MdiChildActivate

在多文档界面 (MDI) 应用程序内激活或关闭 MDI 子窗体时发生。

MenuComplete

当窗体菜单失去焦点时发生。

MenuStart

当窗体菜单接收焦点时发生。

MinimumSizeChanged

在 MinimumSize 属性的值更改后发生。

MouseCaptureChanged

当控件失去鼠标捕获时发生。(从 Control 继承。)

MouseClick

用鼠标单击控件时发生。(从 Control 继承。)

MouseDoubleClick

用鼠标双击控件时发生。(从 Control 继承。)

MouseDown

当鼠标指针位于控件上并按下鼠标键时发生。(从 Control 继承。)

MouseEnter

在鼠标指针进入控件时发生。(从 Control 继承。)

MouseHover

在鼠标指针停放在控件上时发生。(从 Control 继承。)

MouseLeave

在鼠标指针离开控件时发生。(从 Control 继承。)

MouseMove

在鼠标指针移到控件上时发生。(从 Control 继承。)

MouseUp

在鼠标指针在控件上并释放鼠标键时发生。(从 Control 继承。)

MouseWheel

在控件有焦点且鼠标轮移动时发生。(从 Control 继承。)

Move

在移动控件时发生。(从 Control 继承。)

PaddingChanged

在控件空白区更改时发生。(从 Control 继承。)

Paint

在重绘控件时发生。(从 Control 继承。)

ParentChanged

在 Parent 属性值更改时发生。(从 Control 继承。)

PreviewKeyDown

在焦点位于此控件上的情况下,当有按键动作时发生(在 KeyDown 事件之前发生)。(从Control 继承。)

QueryAccessibilityHelp

在 AccessibleObject 为辅助功能应用程序提供帮助时发生。(从 Control 继承。)

QueryContinueDrag

在拖放操作期间发生,并且允许拖动源确定是否应取消拖放操作。(从 Control 继承。)

RegionChanged

当 Region 属性的值更改时发生。(从 Control 继承。)

Resize

在调整控件大小时发生。(从 Control 继承。)

ResizeBegin

窗体进入大小调整模式时发生。

ResizeEnd

窗体退出大小调整模式时发生。

RightToLeftChanged

在 RightToLeft 属性值更改时发生。(从 Control 继承。)

RightToLeftLayoutChanged

更改 RightToLeftLayout 属性值之后发生。

Scroll

用户或代码滚动工作区时发生。(从 ScrollableControl 继承。)

Shown

只要窗体是首次显示就发生。

SizeChanged

在 Size 属性值更改时发生。(从 Control 继承。)

StyleChanged

在控件样式更改时发生。(从 Control 继承。)

SystemColorsChanged

系统颜色更改时发生。(从 Control 继承。)

TabIndexChanged

此 API 支持 产品 基础结构,不能在代码中直接使用。 当 TabIndex 属性的值更改时发生。

TabStopChanged

当 TabStop 属性更改时发生。

TextChanged

在 Text 属性值更改时发生。(从 Control 继承。)

Validated

在控件完成验证时发生。(从 Control 继承。)

Validating

在控件验证时发生。(从 Control 继承。)

VisibleChanged

在 Visible 属性值更改时发生。(从 Control 继承。)

VB.NET 事件的含义

TextBox1_TextChanged() 'TextBox1.text属性改变时发生

Label1_Click() 'Label1被鼠标点击时发生

MenuItem1_Click() 'MenuItem1被鼠标点击时发生

Label1_MouseDown() '鼠标左键在Label1上按下时发生

Label1_DoubleClick() '有点难我也不太清楚,在MSDN上查了下:

双击操作由用户操作系统的鼠标设置确定。用户可以设置两次单击鼠标按钮之间的时间以便将这两次单击认为是双击而不是两次单击。每当双击控件时,就会引发 Click 事件。例如,如果您有 Form 的 Click 和 DoubleClick 事件的事件处理程序,则当双击该窗体并同时调用这两个方法时,会引发 Click 和 DoubleClick 事件。如果双击一个控件并且该控件不支持 DoubleClick 事件,则 Click 事件可能被引发两次。

Label1_MouseUp() '鼠标左键在Label1上放开时发生,一般与Label1_MouseDown()搭配使用

TextBox2_MouseMove() '鼠标停留在TextBox2上时发生

Form1_load() '加载窗体时发生

Form1_click() '点击窗体时发生

Form1_Resize() '窗体调整大小后发生

Form1_KeyPress() '当窗体有焦点键盘有操作时发生

Form1_KeyDown() '当窗体具有焦点并键盘有按键按下时发生

Form1_KeyUp() '当窗体焦点并键盘有按键放开时发生


分享名称:关于vb点虐 事件说明的信息
URL地址:http://kswsj.com/article/ddchgpo.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号