读书人

【200分】怎么在Winform实现类似“摇奖

发布时间: 2012-01-19 00:22:27 作者: rapoo

【200分】请教大家如何在Winform实现类似“摇奖机”的程序,帮顶有分 谢谢
现在有一个datatable,里面有N条数据,希望能实现像娱乐节目里“随机抽选手机号码中奖”的程序,有几点要求:

1-点BUTTON开始抽奖,数据随机的在label(或其它控件)里滚动显示。(关键是要能看到翻动的过程)

2-再次点BUTTON滚动停止,label(或其它控件)里显示被选中的数据。
3-最好有代码

小弟初学,再次感谢帮忙喝帮顶的朋友。!!

[解决办法]
友情UP一下
[解决办法]
一大早帮顶一下吧。
[解决办法]

先赚点分 up下
[解决办法]
mark
[解决办法]
从数据库中获取号码
根据号码显示数字图片
翻转图片
[解决办法]
设个for循环或是定时器控件,这个应该不难吧。
[解决办法]
uppp
[解决办法]
这个程序需要用到多线程,当时用2003做了一个,要是用2005会麻烦一点
[解决办法]
帮顶了
[解决办法]
bang ding le
[解决办法]
我想这个要写一个无限循环来作,在访问数据库的时候,一条一条的读取数据
[解决办法]
这只是我个人认为
[解决办法]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<html>

<head>
<title> 摇奖器 </title>
<script type= "text/javascript ">
<!--
function init(){
document.forms[0].elements[0].value=parseInt(Math.random()*36+1);
document.forms[0].elements[1].value=parseInt(Math.random()*36+1);
document.forms[0].elements[2].value=parseInt(Math.random()*36+1);
document.forms[0].elements[3].value=parseInt(Math.random()*36+1);
document.forms[0].elements[4].value=parseInt(Math.random()*36+1);
document.forms[0].elements[5].value=parseInt(Math.random()*36+1);
document.forms[0].elements[6].value=parseInt(Math.random()*36+1);
timer1=setTimeout( "init() ",0);}
//-->
</script>
</head>

<body>
<center>
<h1 align= "center "> 随机号码(1—36) </h1>

<form align= "center ">
<p> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <input type= "text " size= "1 "> <br>
<input type= "button " value= " 开 始 " OnClick= "init() "> <input type= "button "
value= " 停 止 " OnClick= "clearTimeout(timer1) "> </p>
</form>

<p align= "center ">    </p>
</center>
</body>
</html>


参考下web下的js写法吧!主要是从数据表中取到所以数据读到list <string> 里面,然后随机抽取。
[解决办法]
Imports System.Drawing
Imports System.Drawing.Drawing2D

Public Class form1

Private label1, label2, label3 As New Label
Dim Items As New ArrayList
Dim Switch As Boolean = False
Dim index As Integer = 0

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Switch = Not Switch
If Switch Then
label1.Text = GetLabelText() : label1.Visible = True
label2.Text = GetLabelText() : label2.Visible = True
label3.Text = GetLabelText() : label3.Visible = True

Dim th As Threading.Thread = New Threading.Thread(AddressOf Test)
th.Start()
Else
label1.Visible = False : label2.Visible = False : label3.Visible = False
Panel1.CreateGraphics.DrawString(GetLabelText(), Me.Font, Brushes.Red, 0, 0)
End If
End Sub

Private Sub form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Switch = False
End Sub

Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'初始化Items时可以根据你数据库的手机号进行,我这是测试数据
For i As Integer = 0 To 100
Dim j As Long = 13000000000 + (13999999999 - 13000000000) * Rnd()
Items.Add(j.ToString)
Next
label1.AutoSize = True : label2.AutoSize = True : label3.AutoSize = True
label1.Text = Items(0) : label2.Text = Items(1) : label3.Text = Items(2)
Panel1.Controls.Add(label1) : label1.Location = New Point(0, 0)
Panel1.Controls.Add(label2) : label2.Location = New Point(0, label1.Bottom)
Panel1.Controls.Add(label3) : label3.Location = New Point(0, label2.Bottom)
End Sub

Private Delegate Sub RunMySub()

Private Sub Test()
On Error Resume Next
Do While Switch
Me.Invoke(New RunMySub(AddressOf start))
Threading.Thread.Sleep(10)
Loop
End Sub

Private Sub start()
label1.Top -= 3
If label1.Bottom < 0 Then
label1.Text = GetLabelText()
label1.Top = label3.Bottom
End If
label2.Top -= 3
If label2.Bottom < 0 Then
label2.Text = GetLabelText()
label2.Top = label1.Bottom
End If
label3.Top -= 3
If label3.Bottom < 0 Then
label3.Text = GetLabelText()
label3.Top = label2.Bottom
End If
End Sub

Private Function GetLabelText() As String
index = CType((Items.Count - 1) * Rnd(), Integer)
If index < Items.Count Then Return Items(index) Else Return Items(0)
End Function

End Class

读书人网 >C#

热点推荐