e.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
创建完成后我们来运行程序测试一下,测试成功,
程序在屏幕中不断地来回走动了。
窗体应用技巧二,创建透明的窗体。
创建新工程后,选择Form1窗体,添加Label1、TrackBar1、Timer1控件。为了突出效果为窗体选择一个好看的背景。
相关的属性设置如下:
TrackBar1 Value属性:
TickFrequency: 属性:
Maximum属性: 100
10
100
Label1 Text属性: 选择窗体的透明度:
Timer1 Interval属性: 100
进入代码编辑器,输入代码:
首先进行声明:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim tps As Integer
Dim bol As Boolean
进入TrackBar1_Scroll事件
Private Sub TrackBar1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
Me.Opacity = TrackBar1.Value / 100
Label1.Text = "窗体透明度:" & CStr(Me.Opacity * 100) & "%"
End Sub
进入Timer1_Tick事件
Private Sub Timer1_Tick(ByVal sender As Object, 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.Opac