本篇文章的主要开发环境是Visual Studio Visual Studio系列产品一直以来都提供了强大的控件功能然而我们利用这些控件可以编写出功能强大的应用程序本文主要利用微软的最开发工具为大家展示窗体特效的应用方法为大家介绍创建炫酷的透明化窗体以及浮动型窗体的一些技巧很适开发工具的初学者具有一定的实用价值
打开 Visual Studio 在文件 (File) 菜单上单击新建项目 (New Project) 在新建项目 (New Project) 对话框的模板 (Templates) 窗格中单击 Windows 应用程序(Windows Application)单击确定 (OK)
窗体应用技巧一创建浮动窗体
创建新工程后选择Form窗体添加Timer和Timer控件为窗体选择一个好看的背景当然你也可以使用系统默认的背景
进入代码编辑器输入代码
Public Class Form
Inherits SystemWindowsFormsForm
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
Dim pos As Point = New Point( ) 设置窗体初始位置
MeDesktopLocation = pos
TimerInterval = 设置Timer的值
TimerEnabled = True
TimerInterval =
TimerEnabled = False
End Sub
进入Timer_Tick事件
Private Sub Timer_Tick(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles TimerTick
Dim pos As Point = New Point(MeDesktopLocationX + MeDesktopLocationY + ) 窗体左上方横坐标的timer加
If posX < Or posY < Then
MeDesktopLocation = pos
Else
TimerEnabled = False
TimerEnabled = True
End If
End Sub
进入Timer_Tick事件
Private Sub Timer_Tick(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles TimerTick
Dim pos As Point = New Point(MeDesktopLocationX MeDesktopLocationY ) 窗体的左上方横坐标随着timer减一
If posX > Or posY > Then
MeDesktopLocation = pos
Else
TimerEnabled = True
TimerEnabled = False
End If
End Sub
创建完成后我们来运行程序测试一下测试成功程序在屏幕中不断地来回走动了
窗体应用技巧二创建透明的窗体
创建新工程后选择Form窗体添加LabelTrackBarTimer控件为了突出效果为窗体选择一个好看的背景
相关的属性设置如下
TrackBar Value属性:
TickFrequency: 属性:
Maximum属性:
Label Text属性: 选择窗体的透明度:
Timer Interval属性:
进入代码编辑器输入代码
首先进行声明
Public Class Form
Inherits SystemWindowsFormsForm
Dim tps As Integer
Dim bol As Boolean
进入TrackBar_Scroll事件
Private Sub TrackBar_Scroll(ByVal sender As Object ByVal e As SystemEventArgs) Handles TrackBarScroll
MeOpacity = TrackBarValue /
LabelText = 窗体透明度 & CStr(MeOpacity * ) & %
End Sub
进入Timer_Tick事件
Private Sub Timer_Tick(ByVal sender As Object ByVal e As SystemEventArgs) Handles TimerTick
If bol = False Then
tps = tps +
MeOpacity = tps /
If MeOpacity >= Then
TimerEnabled = False
bol = True
End If
Else
tps = tps
MeOpacity = tps /
If MeOpacity <= Then
TimerEnabled = False
bol = False
End If
End If
End Sub
进入Form_Load事件
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
TimerEnabled = True
End Sub
进入Form_Closing事件
Private Sub Form_Closing(ByVal sender As Object ByVal e As SystemComponentModelCancelEventArgs) Handles MyBaseClosing
TimerEnabled = True
If MsgBox(你确实要关闭窗体吗? MsgBoxStyleOkCancel) = MsgBoxResultOk Then
eCancel = False
Else
TimerEnabled = False
MeOpacity =
tps =
bol = True
eCancel = True
End If
End Sub
创建完成后我们来运行程序测试一下测试成功程序窗体是不是变得透明了通过调节滚动条我们甚至可以使得窗体消失达到完全隐形的目的这是不是很神奇呢?