小編給大家分享一下VB.NET窗體應(yīng)用技巧有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
我們提供的服務(wù)有:網(wǎng)站制作、網(wǎng)站建設(shè)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、臨川ssl等。為1000+企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢(xún)和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的臨川網(wǎng)站制作公司
打開(kāi) Visual Studio 2008在文件 (File) 菜單上,單擊新建項(xiàng)目 (New Project)。 在新建項(xiàng)目 (New Project) 對(duì)話(huà)框的模板 (Templates) 窗格中,單擊 Windows 應(yīng)用程序(Windows Application)。單擊確定 (OK)
VB.NET窗體應(yīng)用技巧一,創(chuàng)建浮動(dòng)窗體。
創(chuàng)建新工程后,選擇Form1窗體,添加Timer1和Timer2控件。為窗體選擇一個(gè)好看的背景,當(dāng)然你也可以使用系統(tǒng)默認(rèn)的背景。
進(jìn)入代碼編輯器,輸入代碼:
Public Class Form1 Inherits System.Windows.Forms.Form Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadDim pos As Point = New Point(100, 50) '設(shè)置窗體初始位置Me.DesktopLocation = posTimer1.Interval = 10 '設(shè)置Timer的值Timer1.Enabled = TrueTimer2.Interval = 10Timer2.Enabled = False End Sub
進(jìn)入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.TickDim pos As Point = New Point(Me.DesktopLocation.X + 2, Me.DesktopLocation.Y + 1) '窗體左上方橫坐標(biāo)的timer1加If pos.X < 600 Or pos.Y < 400 ThenMe.DesktopLocation = posElseTimer1.Enabled = FalseTimer2.Enabled = TrueEnd If End Sub
進(jìn)入Timer2_Tick事件
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.TickDim pos As Point = New Point(Me.DesktopLocation.X - 2, Me.DesktopLocation.Y - 1) '窗體的左上方橫坐標(biāo)隨著timer2減一 If pos.X > 100 Or pos.Y > 50 ThenMe.DesktopLocation = posElseTimer1.Enabled = TrueTimer2.Enabled = False End If End Sub
創(chuàng)建完成后我們來(lái)運(yùn)行程序測(cè)試一下,測(cè)試成功,程序在屏幕中不斷地來(lái)回走動(dòng)了。
VB.NET窗體應(yīng)用技巧二,創(chuàng)建透明的窗體。
創(chuàng)建新工程后,選擇Form1窗體,添加Label1、TrackBar1、Timer1控件。為了突出效果為窗體選擇一個(gè)好看的背景。
相關(guān)的屬性設(shè)置如下:
TrackBar1 Value屬性:
TickFrequency: 屬性:
Maximum屬性: 100
10
100
Label1 Text屬性: 選擇窗體的透明度:
Timer1 Interval屬性: 100
進(jìn)入代碼編輯器,輸入代碼:
首先進(jìn)行聲明:
Public Class Form1 Inherits System.Windows.Forms.FormDim tps As IntegerDim bol As Boolean
進(jìn)入TrackBar1_Scroll事件
Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1TrackBar1.ScrollMe.Opacity = TrackBar1.Value / 100Label1.Text = "窗體透明度:" & CStr(Me.Opacity * 100) & "%" End Sub
進(jìn)入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.TickIf bol = False Thentps
= tps + 1Me.Opacity = tps / 100If Me.Opacity >= 1 ThenTimer1.Enabled = Falsebol = TrueEnd IfElsetps = tps - 1Me.Opacity =
tps / 100If Me.Opacity <= 0 ThenTimer1.Enabled = Falsebol = FalseEndIf End
If End
Sub
進(jìn)入Form1_Load事件
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTimer1.Enabled = TrueEnd Sub
進(jìn)入Form1_Closing事件
Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.ClosingTimer1.Enabled = TrueIf MsgBox("你確實(shí)要關(guān)閉窗體嗎?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Thene.Cancel = FalseElseTimer1.Enabled = FalseMe.Opacity = 1tps = 100bol = Truee.Cancel = True End If End Sub
創(chuàng)建完成后我們來(lái)運(yùn)行程序測(cè)試一下,測(cè)試成功,VB.NET窗體應(yīng)用是不是變得透明了,通過(guò)調(diào)節(jié)滾動(dòng)條我們甚至可以使得窗體消失達(dá)到完全隱形的目的。
以上是“VB.NET窗體應(yīng)用技巧有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!