当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > VB.net2008精彩实例,窗体应用技巧

ASP.NET
FreeTextBox(版本3.1.6)在ASP.Net 2.0中使用方法
.NET 常用功能和代码小结
在 .NET Framework 2.0 中未处理的异常导致基于 ASP.NET 的应用程序意外退出
asp.net IList查询数据后格式化数据再绑定控件
asp.net sql存储过程
asp.net 简单实现禁用或启用页面中的某一类型的控件
asp.net(c#)获取内容第一张图片地址的函数
The remote procedure call failed and did not execute的解决办法
ASP.NET 在线文件管理
asp.net 读取并修改config文件实现代码
ASP.NET Cookie 操作实现
asp.net Silverlight中的模式窗体
Silverlight中动态获取Web Service地址
asp.net Silverlight应用程序中获取载体aspx页面参数
asp.net 水晶报表隔行换色实现方法
asp.net 获取Gridview隐藏列的值
手动把asp.net的类生成dll文件的方法
asp.net 使用ObjectDataSource控件在ASP.NET中实现Ajax真分页
动态指定任意类型的ObjectDataSource对象的查询参数
asp.net Md5的用法小结

ASP.NET 中的 VB.net2008精彩实例,窗体应用技巧


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-23   浏览: 120 ::
收藏到网摘: n/a

本篇文章的主要开发环境是Visual Studio 2008,Visual Studio系列产品一直以来都提供了强大的控件功能,然而我们利用这些控件可以编写出功能强大的应用程序。本文主要利用微软的最新.net开发工具为大家展示窗体特效的应用方法,为大家介绍创建炫酷的透明化窗体以及浮动型窗体的一些技巧。很适合.net开发工具的初学者,具有一定的实用价值。

打开 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

创建完成后我们来运行程序测试一下,测试成功,程序在屏幕中不断地来回走动了。

窗体应用技巧二,创建透明的窗体。

创建新工程后,选择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.Opacity = tps / 100
            If Me.Opacity <= 0 Then
                Timer1.Enabled = False
                bol = False
            End If
        End If
    End Sub

进入Form1_Load事件

以下为引用的内容:
   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
End Sub

进入Form1_Closing事件

以下为引用的内容:
 Private Sub Form1_Closing(ByVal sender As Object, 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

 

创建完成后我们来运行程序测试一下,测试成功,程序窗体是不是变得透明了,通过调节滚动条我们甚至可以使得窗体消失达到完全隐形的目的。这是不是很神奇呢?