用VB.net制作一个小程序(2)

用 VB.net 制作一个小程序( 2 )

---- 制作“ Lucky7 ”程序

作者:高山

它是一个模拟幸运数字投币机的游戏程序。此程序的用户界面中包括两个按钮, 3 个幸运数字框,表示获胜的数字图象以及 Lucky 7 标签。

Public Class Form1

Inherits System.Windows.Forms.Form

Region " Windows 窗体设计器生成的代码 "

Public Sub New ()

MyBase .New()

'该调用是 Windows 窗体设计器所必需的。

InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表。

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 Button1 As System.Windows.Forms.Button

Friend WithEvents Button2 As System.Windows.Forms.Button

Friend WithEvents Label1 As System.Windows.Forms.Label

Friend WithEvents Label2 As System.Windows.Forms.Label

Friend WithEvents Label3 As System.Windows.Forms.Label

Friend WithEvents Label4 As System.Windows.Forms.Label

Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox

  1<system.diagnostics.debuggerstepthrough()> Private  Sub  InitializeComponent() 
  2
  3Dim  resources  As  System.Resources.ResourceManager =  New  System.Resources.ResourceManager(  GetType  (Form1)) 
  4
  5Me  .Button1 =  New  System.Windows.Forms.Button() 
  6
  7Me  .Button2 =  New  System.Windows.Forms.Button() 
  8
  9Me  .Label1 =  New  System.Windows.Forms.Label() 
 10
 11Me  .Label2 =  New  System.Windows.Forms.Label() 
 12
 13Me  .Label3 =  New  System.Windows.Forms.Label() 
 14
 15Me  .Label4 =  New  System.Windows.Forms.Label() 
 16
 17Me  .PictureBox1 =  New  System.Windows.Forms.PictureBox() 
 18
 19Me  .SuspendLayout() 
 20
 21' 
 22
 23'Button1 
 24
 25' 
 26
 27Me  .Button1.Location =  New  System.Drawing.Point(40, 104) 
 28
 29Me  .Button1.Name = "Button1" 
 30
 31Me  .Button1.TabIndex = 0 
 32
 33Me  .Button1.Text = "spin" 
 34
 35' 
 36
 37'Button2 
 38
 39' 
 40
 41Me  .Button2.Location =  New  System.Drawing.Point(40, 152) 
 42
 43Me  .Button2.Name = "Button2" 
 44
 45Me  .Button2.TabIndex = 1 
 46
 47Me  .Button2.Text = "end" 
 48
 49' 
 50
 51'Label1 
 52
 53' 
 54
 55Me  .Label1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle 
 56
 57Me  .Label1.Font =  New  System.Drawing.Font("隶书", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,  CType  (134,  Byte  )) 
 58
 59Me  .Label1.Location =  New  System.Drawing.Point(136, 40) 
 60
 61Me  .Label1.Name = "Label1" 
 62
 63Me  .Label1.TabIndex = 2 
 64
 65Me  .Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 
 66
 67' 
 68
 69'Label2 
 70
 71' 
 72
 73Me  .Label2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle 
 74
 75Me  .Label2.Font =  New  System.Drawing.Font("隶书", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,  CType  (134,  Byte  )) 
 76
 77Me  .Label2.Location =  New  System.Drawing.Point(264, 40) 
 78
 79Me  .Label2.Name = "Label2" 
 80
 81Me  .Label2.TabIndex = 3 
 82
 83Me  .Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 
 84
 85' 
 86
 87'Label3 
 88
 89' 
 90
 91Me  .Label3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle 
 92
 93Me  .Label3.Font =  New  System.Drawing.Font("隶书", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point,  CType  (134,  Byte  )) 
 94
 95Me  .Label3.Location =  New  System.Drawing.Point(400, 40) 
 96
 97Me  .Label3.Name = "Label3" 
 98
 99Me  .Label3.Size =  New  System.Drawing.Size(100, 24) 
100
101Me  .Label3.TabIndex = 4 
102
103Me  .Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter 
104
105' 
106
107'Label4 
108
109' 
110
111Me  .Label4.ForeColor = System.Drawing.Color.Red 
112
113Me  .Label4.Location =  New  System.Drawing.Point(24, 200) 
114
115Me  .Label4.Name = "Label4" 
116
117Me  .Label4.Size =  New  System.Drawing.Size(120, 120) 
118
119Me  .Label4.TabIndex = 5 
120
121Me  .Label4.Text = "Lucky Seven" 
122
123' 
124
125'PictureBox1 
126
127' 
128
129Me  .PictureBox1.Image =  CType  (resources.GetObject("PictureBox1.Image"), System.Drawing.Bitmap) 
130
131Me  .PictureBox1.Location =  New  System.Drawing.Point(208, 120) 
132
133Me  .PictureBox1.Name = "PictureBox1" 
134
135Me  .PictureBox1.Size =  New  System.Drawing.Size(288, 208) 
136
137Me  .PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage 
138
139Me  .PictureBox1.TabIndex = 6 
140
141Me  .PictureBox1.TabStop =  False 
142
143Me  .PictureBox1.Visible =  False 
144
145' 
146
147'Form1 
148
149' 
150
151Me  .AutoScaleBaseSize =  New  System.Drawing.Size(6, 14) 
152
153Me  .ClientSize =  New  System.Drawing.Size(528, 350) 
154
155Me  .Controls.AddRange(  New  System.Windows.Forms.Control() {  Me  .PictureBox1,  Me  .Label4,  Me  .Label3,  Me  .Label2,  Me  .Label1,  Me  .Button2,  Me  .Button1}) 
156
157Me  .Name = "Form1" 
158
159Me  .Text = "Form1" 
160
161Me  .ResumeLayout(  False  ) 
162
163End  Sub 
164
165#  End  Region 
166
167Private  Sub  Label3_Click(  ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  Label3.Click 
168
169End  Sub 
170
171Private  Sub  Button2_Click(  ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  Button2.Click 
172
173End 
174
175End  Sub 
176
177Private  Sub  Button1_Click(  ByVal  sender  As  System.Object,  ByVal  e  As  System.EventArgs)  Handles  Button1.Click 
178
179PictureBox1.Visible =  False  '隐藏图片 
180
181'Rnd函数生成0到1之间的随机数(带有一个小数点和几个小数位),Int函数将这几个数乘以10 
182
183'后在乘以10后再四舍五入得到一个整数,这样就产生了0到9的随机整数. 
184
185Label1.Text =  CStr  (Int(Rnd() * 10))  '选择数字 
186
187Label2.Text =  CStr  (Int(Rnd() * 10)) 
188
189Label3.Text =  CStr  (Int(Rnd() * 10)) 
190
191'如果人一个标题为7则显示图片 
192
193If  (Label1.Text = "7")  Or  (Label2.Text = "7")  Or  (Label3.Text = "7")  Then 
194
195PictureBox1.Visible =  True 
196
197Beep() 
198
199End  If 
200
201End  Sub 
202
203End  Class</system.diagnostics.debuggerstepthrough()>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus