The main development environment for this article is that the Visual Studio 2008,visual Studio series has always provided powerful control capabilities, but we can use these controls to write powerful applications. This article mainly uses Microsoft's latest. NET development tools to show you how to apply the form effects, and to introduce some techniques for creating cool transparent forms and floating forms. Very suitable for the beginners of the. NET development tools, has certain practical value.
Open Visual Studio 2008 on the File menu, click New Project. In the Templates pane of the New Project dialog box, click Windows Application (Windows application). Click OK (OK)
Form Application Tip One, create a floating form.
After you create a new project, select the Form1 form and add the Timer1 and Timer2 controls. Choose a nice background for your form, and of course you can use the system default background.
Into the Code Editor, enter the code:
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 points = New point (100, 50) ' Sets the initial position of the form
Me.desktoplocation = pos
Timer1.interval = 10 ' Set Timer's value
timer1.enabled = True
Timer2.interval = 10
timer2.enabled = False
End Sub
Enter Timer1_Tick Event
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) ' form the upper-left horizontal axis of the timer1 plus
If Pos. X < Or pos. Y < Then
Me.desktoplocation = pos
Else
timer1.enabled = False
timer2.enabled = True
End If
End Sub
Enter Timer2_tick Event
Private Sub Timer2_tick (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Timer2.tick
Dim pos as Point = top left of the New point (me.desktoplocation.x-2, me.desktoplocation.y-1) ' form with Timer2 minus one
If Pos. X > Or pos. Y > Then
Me.desktoplocation = pos
Else
timer1.enabled = True
timer2.enabled = False
End If
End Sub
After the creation, we ran the program to test, the test was successful, and the program kept moving back and forth in the screen.
Form Application Tip Two, create a transparent form.
After you create a new project, select the Form1 form and add the Label1, TrackBar1, Timer1 controls. To highlight the effect, choose a nice background for the form.
The associated property settings are as follows:
TrackBar1 Value property:
Tickfrequency: Properties:
Maximum property: 100
10
100
Label1 Text Property: Select the transparency of the form:
Timer1 Interval Properties: 100
Into the Code Editor, enter the code:
First make a declaration:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim TPs as Integer
Dim Bol as Boolean
Enter Trackbar1_scroll Event
Private Sub Trackbar1_scroll (ByVal sender as Object, ByVal e as System.EventArgs) Handles Trackbar1.scroll
Me.opacity = trackbar1.value/100
Label1.Text = "Form transparency:" & CSTR (Me.opacity *) & "%"
End Sub
Enter Timer1_Tick Event
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
Enter Form1_Load Event
Private Sub Form1_Load (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
timer1.enabled = True
End Sub
Enter Form1_Closing Event
Private Sub form1_closing (ByVal sender as Object, ByVal e as System.ComponentModel.CancelEventArgs) Handles Mybase.closing
timer1.enabled = True
If MsgBox ("Are you sure you want to close the form?") ", 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
When the creation is complete, we run the program to test, the test succeeds, the program form becomes transparent, and by adjusting the scroll bar we can even make the form disappear to complete invisibility. Isn't it amazing?