首页 > 编程 > .NET > 正文

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

2024-07-10 13:01:29
字体:
来源:转载
供稿:网友
用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

<system.diagnostics.debuggerstepthrough()> private sub initializecomponent()

dim resources as system.resources.resourcemanager = new system.resources.resourcemanager(gettype(form1))

me.button1 = new system.windows.forms.button()

me.button2 = new system.windows.forms.button()

me.label1 = new system.windows.forms.label()

me.label2 = new system.windows.forms.label()

me.label3 = new system.windows.forms.label()

me.label4 = new system.windows.forms.label()

me.picturebox1 = new system.windows.forms.picturebox()

me.suspendlayout()

'

'button1

'

me.button1.location = new system.drawing.point(40, 104)

me.button1.name = "button1"

me.button1.tabindex = 0

me.button1.text = "spin"

'

'button2

'

me.button2.location = new system.drawing.point(40, 152)

me.button2.name = "button2"

me.button2.tabindex = 1

me.button2.text = "end"

'

'label1

'

me.label1.borderstyle = system.windows.forms.borderstyle.fixedsingle

me.label1.font = new system.drawing.font("隶书", 9.0!, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ctype(134, byte))

me.label1.location = new system.drawing.point(136, 40)

me.label1.name = "label1"

me.label1.tabindex = 2

me.label1.textalign = system.drawing.contentalignment.middlecenter

'

'label2

'

me.label2.borderstyle = system.windows.forms.borderstyle.fixedsingle

me.label2.font = new system.drawing.font("隶书", 9.0!, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ctype(134, byte))

me.label2.location = new system.drawing.point(264, 40)

me.label2.name = "label2"

me.label2.tabindex = 3

me.label2.textalign = system.drawing.contentalignment.middlecenter

'

'label3

'

me.label3.borderstyle = system.windows.forms.borderstyle.fixedsingle

me.label3.font = new system.drawing.font("隶书", 9.0!, system.drawing.fontstyle.bold, system.drawing.graphicsunit.point, ctype(134, byte))

me.label3.location = new system.drawing.point(400, 40)

me.label3.name = "label3"

me.label3.size = new system.drawing.size(100, 24)

me.label3.tabindex = 4

me.label3.textalign = system.drawing.contentalignment.middlecenter

'

'label4

'

me.label4.forecolor = system.drawing.color.red

me.label4.location = new system.drawing.point(24, 200)

me.label4.name = "label4"

me.label4.size = new system.drawing.size(120, 120)

me.label4.tabindex = 5

me.label4.text = "lucky seven"

'

'picturebox1

'

me.picturebox1.image = ctype(resources.getobject("picturebox1.image"), system.drawing.bitmap)

me.picturebox1.location = new system.drawing.point(208, 120)

me.picturebox1.name = "picturebox1"

me.picturebox1.size = new system.drawing.size(288, 208)

me.picturebox1.sizemode = system.windows.forms.pictureboxsizemode.stretchimage

me.picturebox1.tabindex = 6

me.picturebox1.tabstop = false

me.picturebox1.visible = false

'

'form1

'

me.autoscalebasesize = new system.drawing.size(6, 14)

me.clientsize = new system.drawing.size(528, 350)

me.controls.addrange(new system.windows.forms.control() {me.picturebox1, me.label4, me.label3, me.label2, me.label1, me.button2, me.button1})

me.name = "form1"

me.text = "form1"

me.resumelayout(false)



end sub



#end region



private sub label3_click(byval sender as system.object, byval e as system.eventargs) handles label3.click

end sub



private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click

end

end sub



private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click

picturebox1.visible = false '隐藏图片

'rnd函数生成0到1之间的随机数(带有一个小数点和几个小数位),int函数将这几个数乘以10

'后在乘以10后再四舍五入得到一个整数,这样就产生了0到9的随机整数.

label1.text = cstr(int(rnd() * 10)) '选择数字

label2.text = cstr(int(rnd() * 10))

label3.text = cstr(int(rnd() * 10))

'如果人一个标题为7则显示图片

if (label1.text = "7") or (label2.text = "7") or (label3.text = "7") then

picturebox1.visible = true

beep()

end if

end sub

end class
中国最大的web开发资源网站及技术社区,
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表