VB.NET 2008窗體應用技巧
來源:易賢網(wǎng) 閱讀:875 次 日期:2014-08-20 15:39:04
溫馨提示:易賢網(wǎng)小編為您整理了“VB.NET 2008窗體應用技巧”,方便廣大網(wǎng)友查閱!

打開Visual Studio 2008在文件 (File) 菜單上,單擊新建項目 (New Project)。在新建項目 (New Project) 對話框的模板 (Templates) 窗格中,單擊 Windows 應用程序(Windows Application)。 單擊確定 (OK)

窗體應用技巧一,創(chuàng)建浮動窗體。

創(chuàng)建新工程后,選擇Form1窗體,添加 Timer1和Timer2控件。為窗體選擇一個好看的背景,當然你也可以使用系統(tǒng)默認的背景。

進入代 碼編輯器,輸入代碼:

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

創(chuàng)建完成后我們來運行程序測試一下,測試成功,程序在屏幕中不斷地來回走動了。

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:VB.NET 2008窗體應用技巧

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)