VB.NET浮動窗體創(chuàng)建技巧分享
在VB.NET開發(fā)平臺中,對于窗體的各種操作有了不小的提升。大家可以隨著自己的需求輕松的創(chuàng)建任何形態(tài)的窗體。比如本文介紹的VB.NET浮動窗體等。下面就讓我們一起來分享一下相關(guān)操作技巧。#t#
本篇文章的主要開發(fā)環(huán)境是Visual Studio 2008,Visual Studio系列產(chǎn)品一直以來都提供了強大的控件功能,然而我們利用這些控件可以編寫出功能強大的應(yīng)用程序。本文主要利用微軟的***.net開發(fā)工具為大家展示窗體特效的應(yīng)用方法,為大家介紹創(chuàng)建炫酷的透明化窗體以及浮動型窗體的一些技巧。很適合.net開發(fā)工具的初學(xué)者,具有一定的實用價值。
打開 Visual Studio 2008在文件 (File) 菜單上,單擊新建項目 (New Project)。 在新建項目 (New Project) 對話框的模板 (Templates) 窗格中,單擊 Windows 應(yīng)用程序(Windows Application)。單擊確定 (OK)
創(chuàng)建VB.NET浮動窗體。
創(chuàng)建新工程后,選擇Form1窗體,添加Timer1和Timer2控件。為窗體選擇一個好看的背景,當然你也可以使用系統(tǒng)默認的背景。進入代碼編輯器,輸入VB.NET浮動窗體的創(chuàng)建代碼:
- Public Class Form1
- Inherits System.Windows.Forms.Form
- Private Sub Form1_Load(ByVal sender
As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load- Dim pos As Point = New Point(100, 50)
- '設(shè)置窗體初始位置
- Me.DesktopLocation = pos
- Timer1.Interval = 10
- '設(shè)置Timer的值
- Timer1.Enabled = True
- Timer2.Interval = 10
- Timer2.Enabled = False
- End Sub
進入Timer1_Tick事件
- Private Sub Timer1_Tick(ByVal
sender As System.Object, ByVal
e As System.EventArgs) Handles
Timer1.Tick- Dim pos As Point = New Point
(Me.DesktopLocation.X + 2,
Me.DesktopLocation.Y + 1)- '窗體左上方橫坐標的timer1加
- If pos.X < 600 Or pos.Y < 400 Then
- Me.DesktopLocation = pos
- Else
- Timer1.Enabled = False
- Timer2.Enabled = True
- End If
- End Sub
進入Timer2_Tick事件
- Private Sub Timer2_Tick(ByVal sender
As System.Object, ByVal e As
System.EventArgs) Handles Timer2.Tick- Dim pos As Point = New Point
(Me.DesktopLocation.X - 2, Me.
DesktopLocation.Y - 1)
'窗體的左上方橫坐標隨著timer2減一- If pos.X > 100 Or pos.Y > 50 Then
- Me.DesktopLocation = pos
- Else
- Timer1.Enabled = True
- Timer2.Enabled = False
- End If
- End Sub
創(chuàng)建VB.NET浮動窗體完成后我們來運行程序測試一下,測試成功,程序在屏幕中不斷地來回走動了。