Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object,
1.
2.
3.
ByVal e As System.EventArgs) Handles MyBase.Load
Dim pos As Point = New Point(100, 50) '设置窗体初始位置
Me.DesktopLocation = pos
Timer1.Interval = 10 '设置Timer的值
Timer1.Enabled = True
Timer2.Interval = 10
Timer2.Enabled = False
End Sub
1.
2.
3.
4.
5.
6.
7.
8.
进入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
1.
Handles Timer1.Tick
Dim pos As Point = New Point(Me.DesktopLocation.X + 2, Me.DesktopLocation.Y + 1)
1.
2.
'窗体左上方横坐标的timer1加
If pos.X < 600 Or pos.Y < 400 Then
Me.DesktopLocation = pos
Else
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub
1.
2.
3.
4.
5.
6.
7.
8.
进入Timer2_Tick事件
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
1.
Handles Timer2.Tick
Dim pos As Point = New Point(Me.DesktopLocation.X - 2, Me.DesktopLocation.Y - 1)
1.
2.
3.
'窗体的左上方横坐标随着timer2减一
If pos.X > 100 Or pos.Y > 50 Then
Me.DesktopLocation = pos
Else
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub
Public Class Form1
Inherits System.Windows.Forms.Form
Dim tps As Integer
Dim bol As Boolean
1.
2.
3.
4.
进入TrackBar1_Scroll事件
Private Sub TrackBar1_Scroll(ByVal sender As Object,
1.
ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Me.Opacity = TrackBar1.Value / 100
Label1.Text = "窗体透明度:" & CStr(Me.Opacity * 100) & "%"
End Sub
1.
2.
3.
4.
进入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As Object,
1.
ByVal e As System.EventArgs) Handles Timer1.Tick
If bol = False Then
tps = tps + 1
Me.Opacity = tps / 100
If Me.Opacity >= 1 Then
Timer1.Enabled = False
bol = True
End If
Else
tps = tps - 1
Me.Opacity = tps / 100
If Me.Opacity <= 0 Then
Timer1.Enabled = False
bol = False
End If
End If
End Sub
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
进入Form1_Load事件
Private Sub Form1_Load(ByVal sender As System.Object,
1.
ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub
1.
2.
3.
进入Form1_Closing事件
Private Sub Form1_Closing(ByVal sender As Object,
1.
ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Timer1.Enabled = True
If MsgBox("你确实要关闭窗体吗?", MsgBoxStyle.OkCancel) = MsgBoxResult.Ok Then
e.Cancel = False
Else
Timer1.Enabled = False
Me.Opacity = 1
tps = 100
bol = True
e.Cancel = True
End If
End Sub