[这个贴子最后由无条件为你在 2006/04/05 09:58pm 第 3 次编辑]
公布原代码:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
';该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
';在 InitializeComponent() 调用之后添加任何初始化
End Sub
';窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
';Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
';注意: 以下过程是 Windows 窗体设计器所必需的
';可以使用 Windows 窗体设计器修改此过程。
';不要使用代码编辑器修改它。
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Label3 = New System.Windows.Forms.Label
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.SuspendLayout()
';
';Label1
';
Me.Label1.AutoSize = True
Me.Label1.Font = New System.Drawing.Font("华文行楷", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Yellow
Me.Label1.Location = New System.Drawing.Point(32, 32)
Me.Label1.Name = "Label1"
Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label1.Size = New System.Drawing.Size(83, 30)
Me.Label1.TabIndex = 0
Me.Label1.Text = "用户名"
';
';Label2
';
Me.Label2.AutoSize = True
Me.Label2.Font = New System.Drawing.Font("华文行楷", 18.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.ForeColor = System.Drawing.Color.Yellow
Me.Label2.Location = New System.Drawing.Point(32, 72)
Me.Label2.Name = "Label2"
Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Label2.Size = New System.Drawing.Size(82, 30)
Me.Label2.TabIndex = 0
Me.Label2.Text = "密 码"
';
';TextBox1
';
Me.TextBox1.AutoSize = False
Me.TextBox1.Location = New System.Drawing.Point(128, 32)
Me.TextBox1.MaxLength = 5
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(112, 24)
Me.TextBox1.TabIndex = 1
Me.TextBox1.Text = ""
';
';TextBox2
';
Me.TextBox2.AutoSize = False
Me.TextBox2.CharacterCasing = System.Windows.Forms.CharacterCasing.Lower
Me.TextBox2.Location = New System.Drawing.Point(128, 72)
Me.TextBox2.MaxLength = 10
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(112, 24)
Me.TextBox2.TabIndex = 2
Me.TextBox2.Text = ""
';
';Button1
';
Me.Button1.BackColor = System.Drawing.Color.Red
Me.Button1.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.Button1.Location = New System.Drawing.Point(56, 120)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 32)
Me.Button1.TabIndex = 3
Me.Button1.Text = "进 入"
Me.Button1.TextAlign = System.Drawing.ContentAlignment.BottomCenter
';
';Button2
';
Me.Button2.BackColor = System.Drawing.Color.Chocolate
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button2.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.Button2.Location = New System.Drawing.Point(160, 120)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(72, 32)
Me.Button2.TabIndex = 4
Me.Button2.Text = "退 出"
Me.Button2.TextAlign = System.Drawing.ContentAlignment.BottomCenter
';
';Label3
';
Me.Label3.BackColor = System.Drawing.SystemColors.Window
Me.Label3.Cursor = System.Windows.Forms.Cursors.Hand
Me.Label3.ForeColor = System.Drawing.Color.Transparent
Me.Label3.Image = CType(resources.GetObject("Label3.Image"), System.Drawing.Image)
Me.Label3.ImageAlign = System.Drawing.ContentAlignment.TopCenter
Me.Label3.Location = New System.Drawing.Point(80, 8)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(112, 16)
Me.Label3.TabIndex = 5
';
';Timer1
';
Me.Timer1.Enabled = True
';
';Form1
';
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.BackColor = System.Drawing.Color.Green
Me.CancelButton = Me.Button2
Me.ClientSize = New System.Drawing.Size(296, 182)
Me.ControlBox = False
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.Button2)
Me.KeyPreview = True
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "Form1"
Me.ShowInTaskbar = False
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "→无条件⊙欢迎您!联系QQ:335342"
Me.TopMost = True
Me.ResumeLayout(False)
End Sub
#End Region
Dim df, rndd As Boolean
Dim ox, oy As Integer
Function mwy()
Button1.Hide()
Button2.Hide()
Label2.Hide()
TextBox1.Hide()
TextBox2.Hide()
Me.ClientSize = New System.Drawing.Size(104, 128) ';改变原窗体大小。
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
Me.BackColor = System.Drawing.SystemColors.Window
Me.TransparencyKey = System.Drawing.Color.Transparent
Me.ResumeLayout(False)
Me.Label3.Show() ';显示Label3控件
Me.Label3.Dock = System.Windows.Forms.DockStyle.Fill ';设置布满窗体
rndd = True
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Label3.Hide() ';载入时最先执行隐藏Label3的操作。
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
MsgBox(Chr(13) & "您已退出成功,欢迎下次再来!", MsgBoxStyle.Information, "→无条件为你⊙欢迎您!联系QQ:335342")
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (TextBox2.Text = "mwy") Then
MsgBox(Chr(13) & Chr(9) & "无条件为你,欢迎您!" & Chr(13) & Chr(13) & "今天是:" & Now.Year & "年" & Now.Month & "月" & Now.Day & "日,已经登录成功! ", MsgBoxStyle.Question, "→无条件为你⊙欢迎您!联系QQ:335342")
mwy()
';这里有改动,有删节。原来引用数据库进行验证,这里没有必要。
Else
MsgBox(Chr(13) & "用户名或密码,严重错误,请向QQ335342联系索取!", MsgBoxStyle.Critical, "→无条件为你⊙欢迎您!联系QQ:335342")
End If
End Sub
Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Button1.BackColor = System.Drawing.Color.DarkOrange
Button1.Font = New System.Drawing.Font("楷体_GB2312", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Button1.Text = "喜欢你"
End Sub
Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Me.Button1.BackColor = System.Drawing.Color.Red
Me.Button1.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.Text = "进 入"
End Sub
Private Sub Label3_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label3.DoubleClick
MsgBox(Chr(13) & "亲爱的,你想做什么呢?发现你双击了我!想关闭我请按键盘上的 Q 键!", MsgBoxStyle.Critical, "→无条件为你⊙程序设计,联系QQ335342")
End Sub
Private Sub Label3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseDown
If e.Button = Windows.Forms.MouseButtons.Left Then
ox = e.X
oy = e.Y
df = True ';鼠标按下标记。
Else
MsgBox(Chr(13) & "欢迎" & TextBox1.Text & "的大驾光临!今天是:" & Now.Year & "年" & Now.Month & "月" & Now.Day & "日", MsgBoxStyle.Information, "→无条件为你⊙程序设计,联系QQ335342")
End If
End Sub
Private Sub Label1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label1.MouseUp
If e.Button = Windows.Forms.MouseButtons.Left Then
df = False ';鼠标抬起标记。
End If
End Sub
Private Sub Label3_MouseMove1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Label3.MouseMove
If df Then ';如果条件成立,则说明用鼠标拖曳过“小天使”,所以应做相应的移动。
Me.Left += e.X - ox
Me.Top += e.Y - oy
End If
End Sub
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Dim SC_CLOSE As Integer = 61536
Dim WM_SYSCOMMAND As Integer = 274
';判断是系统消息,是不是关闭窗体?,使Alt+F4无效
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_CLOSE Then
MsgBox(Chr(13) & "呵呵,干什么呢?想用Alt+F4关闭我,没门!你用鼠标双击我试试!", MsgBoxStyle.AbortRetryIgnore, "→无条件为你⊙程序设计,联系QQ335342")
Exit Sub
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
If Char.ToLower(e.KeyChar) <> "q" Then
If rndd Then MsgBox(Chr(13) & "呵呵,干什么呢?发现你按了键盘!请按Q键关闭我!", MsgBoxStyle.AbortRetryIgnore, "→无条件为你⊙程序设计,联系QQ335342")
Else
MsgBox(Chr(13) & "亲爱的,轻轻的我走了,正如我轻轻的来……", MsgBoxStyle.Critical, "→无条件为你⊙程序设计,联系QQ335342")
Me.Close()
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If rndd Then
If (Me.Top < 0) Then
Me.Left += (-1) ^ Int(Rnd(1)) * CInt(Rnd() * 3)
Me.Top += CInt(Rnd() * 5)
ElseIf Me.Top > Screen.PrimaryScreen.Bounds.Height - Me.Height Then
Me.Left += (-1) ^ Int(Rnd()) * CInt(Rnd() * 3)
Me.Top -= CInt(Rnd() * 5)
ElseIf Me.Left < 0 Then
Me.Left += CInt(Rnd() * 5)
Me.Top += (-1) ^ Int(Rnd(1)) * CInt(Rnd() * 3) ';
ElseIf Me.Left > Screen.PrimaryScreen.Bounds.Width - Me.Width Then
Me.Left -= CInt(Rnd() * 3)
Me.Top += (-1) ^ Int(Rnd(1)) * CInt(Rnd() * 3)
Else
';正常情况。
Me.Left += (-1) ^ Int(Rnd(1)) * CInt(Rnd() * 3)
Me.Top += (-1) ^ Int(Rnd(1)) * CInt(Rnd() * 3) ';
End If
End If
End Sub
End Class
其中包含有随机数的那段定时器代码写得不怎么好。主要是不能很好的控制小天使的起落。
密码正确进入后,会在桌面处产生一只飞翔的小天使,不停的飞,飞累了会落在屏幕右下角。双击右击都会有提示,按“Q”键关闭。
其实自我感觉用VB.net编写程序很简单,事件都是系统自带的,由于是事先定义好的,所以从开发时间角度来说,效率比C++高得多。我用半个小时写的程序,如果改用C++至少需要三天。
为了便于初学者学者,程序关键部分都有注释,让高手们见笑了!
VB.net有很好的操作界面,每输入命令的前几个字符,后面会给出提示,如果格式不对或语法错误会自动产生正确的格式和语法。实在解决不了的错误会事先加出下划线给出提示,不像C++那样只有在编译的时候才能发现错误。编写这个小程序刚刚开始用了两个小时,现在如果再让我写类似的程序只需要20分钟就可以搞定。 |