關于vb.netdelay的信息

vb.net使用Sleep后有些代碼沒有執行!

在VB.NET中,帶框架窗體的大小是不能為0的,要想做到高、寬都為0,需要自己重繪一個無邊框窗體,用外置圖片來繪制,配合PS做一些圖片,既可以換膚還能做的很漂亮。

成都創新互聯公司成立與2013年,先為張家港等服務建站,張家港等地企業,進行企業商務咨詢服務。為張家港企業網站制作PC+手機+微官網三網同步一站式服務解決您的所有建站問題。

按當前代碼修改,你把下面的代碼粘回去就可以了,窗體的高和寬達到最小時,循環會自己退出,避免無限循環;

Select?Case?2

Case?Is?=?1

Dim?w?As?Integer?=?Me.Width

Do

Me.Width?-=?5?:?w?-=?5

Threading.Thread.Sleep(3)

Loop?While?Me.Width?=?w

Case?Is?=?2

Dim?h?As?Integer?=?Me.Height

Do

Me.Height?-=?5?:?h?-=?5

Threading.Thread.Sleep(3)

Loop?While?Me.Height?=?h

Case?Is?=?3

Do

Me.Opacity?-=?0.05

Threading.Thread.Sleep(120)

Loop?Until?Me.Opacity?=?0

End?Select

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

一委托:此示例演示如何將方法與委托關聯然后通過委托調用該方法。

創建委托和匹配過程

創建一個名為 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.net 等待上個命令執行完成,進行下個命令

送你一個延遲函數單位毫秒

Public Sub delay(ByRef Interval As Double)

On Error Resume Next

Dim time As DateTime = DateTime.Now

Dim Span As Double = Interval * 10000000 '因為時間是以100納秒為單位。

While ((DateTime.Now.Ticks - time.Ticks) Span)

Application.DoEvents()

End While

End Sub

如何正確理解VB.NET延時函數

第一個for完成對delay_time參數的控制,即共循環多少次內部循環

第二個for(內部循環),完成對j從0到199的控制,共循環200次。

翻譯成匯編就是:

(R0為傳遞參數)

DELAY:

MOV R1,#200

DJNZ R1,$

DJNZ R0,DELAY

RET

新聞標題:關于vb.netdelay的信息
網站地址:http://m.kartarina.com/article48/hgsphp.html

成都網站建設公司_創新互聯,為您提供云服務器手機網站建設微信小程序建站公司網頁設計公司網站排名

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

h5響應式網站建設
主站蜘蛛池模板: 无码任你躁久久久久久老妇| 国产高清不卡无码视频| 国产精品va无码一区二区| 日韩av无码中文字幕| 日韩少妇无码喷潮系列一二三| 国产网红主播无码精品| 99久久亚洲精品无码毛片| 潮喷大喷水系列无码久久精品| 久久久久亚洲精品无码蜜桃| 亚洲乱亚洲乱少妇无码| 亚洲中文字幕久久精品无码A| 国产精品无码无卡无需播放器| 精品久久久久久无码不卡| 无码人妻一区二区三区免费视频| 2021无码最新国产在线观看| 亚洲国产精品无码专区| 精品无人区无码乱码大片国产| 无码人妻一区二区三区兔费| 亚洲国产成人精品无码区在线观看 | 久久午夜无码免费| 亚洲av无码一区二区三区天堂 | 国产精品成人无码久久久| 无码国内精品人妻少妇蜜桃视频| 亚洲成a人在线看天堂无码| 成人无码区免费视频观看| 中文午夜人妻无码看片| 中出人妻中文字幕无码 | 精品无码无人网站免费视频| 国产在线拍揄自揄拍无码| 无码 免费 国产在线观看91| 好爽毛片一区二区三区四无码三飞| 精品无码AV一区二区三区不卡| 久久久久亚洲av无码专区喷水| 久久久久久久无码高潮| 无码国产福利av私拍| 色欲A∨无码蜜臀AV免费播 | 久久午夜无码鲁丝片直播午夜精品| 少妇性饥渴无码A区免费| 在线高清无码A.| 久久久久亚洲Av片无码v| 久久亚洲精品成人无码网站|