计算机二级VB.NET2008精彩实例窗体应用技巧
来源:优易学  2011-5-27 17:26:55   【优易学:中国教育考试门户网】   资料下载   IT书店

  打开 Visual Studio 2008在文件 (File) 菜单上,单击新建项目 (New Project)。 在新建项目 (New Project) 对话框的模板 (Templates) 窗格中,单击 Windows 应用程序(Windows Application)。单击确定 (OK)
  窗体应用技巧一,创建浮动窗体。
  创建新工程后,选择Form1窗体,添加Timer1和Timer2控件。为窗体选择一个好看的背景,当然你也可以使用系统默认的背景。
  进入代码编辑器,输入代码:
  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) '设置窗体初始位置
  Me.DesktopLocation = pos
  Timer1.Interval = 10 '设置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

[1] [2] 下一页

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训