熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

VB.net2008精彩實例,窗體應用技巧

2022-06-13   來源: .NET編程 

  本篇文章的主要開發環境是Visual Studio Visual Studio系列產品一直以來都提供了強大的控件功能然而我們利用這些控件可以編寫出功能強大的應用程序本文主要利用微軟的最開發工具為大家展示窗體特效的應用方法為大家介紹創建炫酷的透明化窗體以及浮動型窗體的一些技巧很適開發工具的初學者具有一定的實用價值

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

  窗體應用技巧一創建浮動窗體

  創建新工程後選擇Form窗體添加Timer和Timer控件為窗體選擇一個好看的背景當然你也可以使用系統默認的背景

  進入代碼編輯器輸入代碼

    Public Class Form
    Inherits SystemWindowsFormsForm  
Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
        Dim pos As Point = New Point( ) 設置窗體初始位置
        MeDesktopLocation = pos
        TimerInterval = 設置Timer的值
        TimerEnabled = True
        TimerInterval =
        TimerEnabled = False
    End Sub
  
  進入Timer_Tick事件
  
   Private Sub Timer_Tick(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles TimerTick
        Dim pos As Point = New Point(MeDesktopLocationX + MeDesktopLocationY + ) 窗體左上方橫坐標的timer
        If posX < Or posY < Then
            MeDesktopLocation = pos
        Else
            TimerEnabled = False
            TimerEnabled = True
        End If
    End Sub
  
  進入Timer_Tick事件

    Private Sub Timer_Tick(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles TimerTick

        Dim pos As Point = New Point(MeDesktopLocationX MeDesktopLocationY ) 窗體的左上方橫坐標隨著timer減一
      

  If posX > Or posY > Then
            MeDesktopLocation = pos
        Else
            TimerEnabled = True
            TimerEnabled = False
        End If
    End Sub
  
  創建完成後我們來運行程序測試一下測試成功程序在屏幕中不斷地來回走動了

  窗體應用技巧二創建透明的窗體

  創建新工程後選擇Form窗體添加LabelTrackBarTimer控件為了突出效果為窗體選擇一個好看的背景

  相關的屬性設置如下
    TrackBar Value屬性:
    TickFrequency: 屬性:
    Maximum屬性:
   
   
    Label Text屬性: 選擇窗體的透明度:
    Timer Interval屬性:

  進入代碼編輯器輸入代碼

  首先進行聲明
  
   Public Class Form
    Inherits SystemWindowsFormsForm
    Dim tps As Integer
Dim bol As Boolean
  
  進入TrackBar_Scroll事件
 
 Private Sub TrackBar_Scroll(ByVal sender As Object ByVal e As SystemEventArgs) Handles TrackBarScroll
        MeOpacity = TrackBarValue /
        LabelText = 窗體透明度 & CStr(MeOpacity * ) & %
End Sub
  
  進入Timer_Tick事件

    Private Sub Timer_Tick(ByVal sender As Object ByVal e As SystemEventArgs) Handles TimerTick
        If bol = False Then
            tps = tps +
            MeOpacity = tps /
            If MeOpacity >= Then
                TimerEnabled = False
                bol = True
            End If
        Else
            tps = tps
            MeOpacity = tps /
            If MeOpacity <= Then
                TimerEnabled = False
                bol = False
            End If
        End If
    End Sub

  
  進入Form_Load事件

    Private Sub Form_Load(ByVal sender As SystemObject ByVal e As SystemEventArgs) Handles MyBaseLoad
        TimerEnabled = True
End Sub

  
  進入Form_Closing事件
 
 Private Sub Form_Closing(ByVal sender As Object ByVal e As SystemComponentModelCancelEventArgs) Handles MyBaseClosing
        TimerEnabled = True
        If MsgBox(你確實要關閉窗體嗎? MsgBoxStyleOkCancel) = MsgBoxResultOk Then
            eCancel = False
        Else
            TimerEnabled = False
            MeOpacity =
            tps =
            bol = True
            eCancel = True
        End If
End Sub
  
  創建完成後我們來運行程序測試一下測試成功程序窗體是不是變得透明了通過調節滾動條我們甚至可以使得窗體消失達到完全隱形的目的這是不是很神奇呢?

  


From:http://tw.wingwit.com/Article/program/net/201311/11580.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.