Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
'继承得到一个窗体
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New ( )
MyBase.New ( )
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent ( )
'在 InitializeComponent ( ) 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose ( ByVal disposing As Boolean )
If disposing Then
If Not ( components Is Nothing ) Then
components.Dispose ( )
End If
End If
MyBase.Dispose ( disposing )
End Sub
'在Windows 窗体创建组件和定义相关变量
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents Label1 As System.Windows.Forms.Label
Dim temp As Integer = 100
Dim flag As Boolean = True
Private Sub InitializeComponent ( )
'初始化各组件
Me.components = New System.ComponentModel.Container ( )
Me.Button1 = New System.Windows.Forms.Button ( )
Me.Button2 = New System.Windows.Forms.Button ( )
Me.Timer1 = New System.Windows.Forms.Timer ( Me.components )
Me.Label1 = New System.Windows.Forms.Label ( )
Me.SuspendLayout ( )
Me.Button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button1.Location = New System.Drawing.Point ( 86 , 64 )
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size ( 96 , 36 )
Me.Button1.TabIndex = 0
Me.Button1.Text = "启动"
Me.Button2.FlatStyle = System.Windows.Forms.FlatStyle.Flat
Me.Button2.Location = New System.Drawing.Point ( 86 , 116 )
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size ( 96 , 36 )
Me.Button2.TabIndex = 1
Me.Button2.Text = "停止"
Me.Label1.Location = New System.Drawing.Point ( 168 , 180 )
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 2
Me.Label1.Text = "Label1"
Me.AutoScaleBaseSize = New System.Drawing.Size ( 6 , 14 )
Me.ClientSize = New System.Drawing.Size ( 266 , 223 )
'在窗体中加入可视化组件
Me.Controls.AddRange ( New System.Windows.Forms.Control ( )
{Me.Label1 , Me.Button2 , Me.Button1} )
Me.MaximizeBox = False
Me.Name = "Form1"
Me.Text = "VB.NET实现淡入淡出的窗体效果"
Me.ResumeLayout ( False )
End Sub
#End Region
'启动定时器
Private Sub Button1_Click ( ByVal sender As Object , ByVal e As
System.EventArgs ) Handles Button1.Click
Timer1.Enabled = True
End Sub
'关闭定时器,停止窗体淡入淡出
Private Sub Button2_Click ( ByVal sender As Object , ByVal e As
System.EventArgs ) Handles Button2.Click
Timer1.Enabled = False
End Sub
'调整窗体属性,实现窗体淡入淡出特效
Private Sub Timer1_Tick ( ByVal sender As Object , ByVal e As
System.EventArgs ) Handles Timer1.Tick
If flag = True Then
temp = temp - 1
Me.Opacity = temp / 100
Label1.Text = ( temp / 100 ).ToString ( )
If temp = 0 Then
flag = False
End If
Else
temp = temp + 1
Me.Opacity = temp / 100
Label1.Text = ( temp / 100 ).ToString ( )
If temp = 100 Then
flag = True
End If
End If
End Sub
End Class
Module Module1
Sub Main ( )
Application.Run ( new Form1 ( ) )
End sub
End Module
[/CODE]