精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網(wǎng)站建設(shè)資訊

NEWS

網(wǎng)站建設(shè)資訊

vb.netof語法 vbforto語句

vb.net中如何用事件和委托,會C#中的事件和委托,但不知VB.net中的語法,望給個簡單的例子熟悉語法。

一委托:此示例演示如何將方法與委托關(guān)聯(lián)然后通過委托調(diào)用該方法。

十載專業(yè)網(wǎng)站制作公司歷程,堅持以創(chuàng)新為先導(dǎo)的網(wǎng)站服務(wù),服務(wù)超過上千企業(yè)及個人,涉及網(wǎng)站設(shè)計、手機APP定制開發(fā)、微信開發(fā)、平面設(shè)計、互聯(lián)網(wǎng)整合營銷等多個領(lǐng)域。在不同行業(yè)和領(lǐng)域給人們的工作和生活帶來美好變化。

創(chuàng)建委托和匹配過程

創(chuàng)建一個名為 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

定義一個方法,該方法創(chuàng)建該委托的實例并通過調(diào)用內(nèi)置的 Invoke 方法調(diào)用與該委托關(guān)聯(lián)的方法。

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

二、事件

下面的示例程序闡釋如何在一個類中引發(fā)一個事件,然后在另一個類中處理該事件。AlarmClock 類定義公共事件 Alarm,并提供引發(fā)該事件的方法。AlarmEventArgs 類派生自 EventArgs,并定義 Alarm 事件特定的數(shù)據(jù)。WakeMeUp 類定義處理 Alarm 事件的 AlarmRang 方法。AlarmDriver 類一起使用類,將使用 WakeMeUp 的 AlarmRang 方法設(shè)置為處理 AlarmClock 的 Alarm 事件。

該示例程序使用事件和委托和引發(fā)事件中詳細(xì)說明的概念。

示例

' 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.NET的語法解析程序

  比較長 不過支持全部的關(guān)鍵字 直接就可以用了 using System;using System Text;using System Text RegularExpressions;

namespace Com OSLeague Component{/// summary/// 語法分析器 將所有Code根據(jù)語法進行變色/// list type= VB 支持VB NET/list/// list type= CS 支持CS/list/// author掉掉/author/// date 年 月 日/date/// Memo/// 練習(xí)正則表達式/// /Memo/// /summarypublic class CodeAnalysis{

////定義HTML開始和結(jié)束的語句 用于語法變色//

const string TAG_FNTRED = @ font color= red ;const string TAG_FNTBLUE = @ font color= blue ;const string TAG_FNTGRN = @ font color= green ;const string TAG_FNTMRN = @ font color= maroon ;const string TAG_FNTBLACK = @ font color= black ;const string TAG_EFONT = @ /font ;const string TAG_SPNYELLOW = @ span style= background color: yellow; ;const string TAG_ESPAN = @ /span ;const string TAG_B = @ b ;const string TAG_EB = @ /b ;const string TAG_MENT = @ font colr=# ;const string TAG_EMENT = @ /font ;

//

public CodeAnalysis(){//// TODO: 在此處添加構(gòu)造函數(shù)邏輯//}

/// summary/// 處理VB NET代碼 彩色化 /// /summary/// param name= Code 傳入的Code/param/// returns處理過后的代碼/returnspublic string ParseVB(string Code){////定義VB NET中關(guān)鍵字 將其存為數(shù)組//

string[] VB_Keyword = new string[]{ AddHandler AddressOf AndAlso Alias And Ansi As Assembly Auto Boolean ByRef Byte ByVal Call Case Catch CBool CByte CChar CDate CDec CDbl Char CInt Class CLng CObj Const CShort CSng CStr CType Date Decimal Declare Default Delegate Dim DirectCast Do Double Each Else ElseIf End Enum Erase Error Event Exit False Finally For Friend Function Get GetType GoTo Handles If Implements Imports In Inherits Integer Interface Is Let Lib Like Long Loop Me Mod Module MustInherit MustOverride MyBase MyClass Namespace New Next Not Nothing NotInheritable NotOverridable Object On Option Optional Or OrElse Overloads Overridable Overrides ParamArray Preserve Private Property Protected Public RaiseEvent ReadOnly ReDim RemoveHandler Resume Return Select Set Shadows Shared Short Single Static Step Stop String Structure Sub SyncLock Then Throw To True Try TypeOf Unicode Until Variant When While With WithEvents WriteOnly Xor };

////設(shè)定轉(zhuǎn)換代碼顏色//

lishixinzhi/Article/program/net/201311/14615

VB.NET 中的Of是什么意思

泛型參數(shù),表示一種特定類型,通常用于集合List, Dictionary之類的。

原型:Dictionary(Of TKey, TValue)

原型不能直接使用,必須給TKey, TValue指定一個類型(Type)

強類型字典:Dictionary(Of String, String)

表示鍵和值都為String類型的字典。


本文題目:vb.netof語法 vbforto語句
文章來源:http://m.jcarcd.cn/article/dddsdsh.html
主站蜘蛛池模板: 午夜国产在线观看 | 日本国产在线 | 国产精品综合色 | 老色鬼精品| 国产亚洲一 | 欧美在线精品αⅴ | 91天堂网 | 欧美自拍无毒不卡 | 午夜免费福利在 | 91免费网址| 岛国三级在 | 老女人丨91丨九色 | 日本一本在 | 日本高清xxxxx | 国产欧美三级亚洲 | 精品午夜日韩 | 国产乱理伦片在线 | 日韩精品永 | 亚洲无码影院中文字幕 | 国产外部专区一朋友 | 国产高清 | 日本高清视频色惰 | 国产精品在里面 | 国产欧美日韩乱伦 | 日本在线成人短视频 | 成人偷窥自拍视频在 | 欧美另类日韩成人 | 福利色导航| 精品亚洲国产 | 日韩免费AV | 成人午夜网址 | 日韩中文字幕网站 | 国产精品大神 | 欧美日韩一区在线 | 天美影视| 伦理片mp4| 国产高清免费视频 | 国产专区三妖 | 国产原创精品在线 | 国产福利发布页 | 97在线人人 |