게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
c# 로또 번호 생성기 소스인데..궁금증이있습니다
게시물ID : programmer_17558짧은주소 복사하기
작성자 : 토왕
추천 : 0
조회수 : 1748회
댓글수 : 2개
등록시간 : 2016/06/09 21:21:15
옵션
  • 본인삭제금지
using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;

using System.Resources;
using System.Reflection;
using System.IO;

namespace Lotto
{
public partial class Form1 : Form
{
ArrayList al;
bool isStarted = false;

private delegate void LabelView1(Label label, string message1);
private delegate void TextBoxView1(TextBox textBox, string message1);

public Form1()
{
InitializeComponent();

return;
}
private void button1_Click(object sender, EventArgs e)
{
if (!this.isStarted)
{
                pictureBox1.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));
                pictureBox2.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));
                pictureBox3.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));
                pictureBox4.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));
                pictureBox5.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));
                pictureBox6.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.blank.gif"));

                this.label2.Text = "";
                this.label3.Text = "";
                Thread work = new Thread(doWork);
                work.Start();

}
}

public void doWork()
{



this.isStarted = true;
al = new ArrayList();
Random rd = new Random(DateTime.Now.Millisecond);
for (int i = 0; i < 6; i++)
{
MakeNum(i, rd);
Thread.Sleep(200);
}

al.Sort();
for (int j = 0; j < al.Count; j++)
{
                if (j == 0)
                    pictureBox1.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));
                if (j == 1)
                    pictureBox2.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));
                if (j == 2)
                    pictureBox3.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));

                if (j == 3)
                    pictureBox4.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));
                if (j == 4)
                    pictureBox5.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));
                if (j == 5)
                    pictureBox6.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + al[j].ToString() + ".gif"));
            }
this.Invoke(new LabelView1(SetMessage), this.label1, "안상훈대박!!");
this.isStarted = false;
}

public void MakeNum(int i, Random rd)
{
while (true)
{
int n = rd.Next(1, 45);
if (!isNumExists(n))
{
al.Add(n);
int iv = 400;

for (int j = 1; j <= n; j++)
{
                        if (i == 0)
                            pictureBox1.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
                        if (i == 1)
                            pictureBox2.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
                        if (i == 2)
                            pictureBox3.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
                        if (i == 3)
pictureBox4.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
if (i == 4)
pictureBox5.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
if (i == 5)
pictureBox6.Image = new Bitmap(Assembly.GetExecutingAssembly().GetManifestResourceStream("Lotto.ball" + j + ".gif"));
Thread.Sleep(iv/n);
}
break;
}
//this.Invoke(new LabelView1(SetMessageAll), this.label2, i.ToString() +": 중복발생 [" + n + "], 다시 시도\r\n");
}
}
public bool isNumExists(int num)
{
for (int j = 0; j < this.al.Count; j++)
{
if (this.al[j].Equals(num))
return true;
}
return false;
}

private void SetMessage(Label label, string message)
{
label.Text  = ""+message+"";
}

private void SetMessageAll(Label label, string message)
{
label.Text += "" + message + "";
}

private void SetMessageBlank(Label label, string message)
{
label.Text = "" + message + "";
}

private void SetTextBoxAll(TextBox textBox, string message)
{
textBox.Text += "" + message + "";
}

private void Form1_Load(object sender, EventArgs e)
{


//this.ClientSize = new Size(image.Width, image.Height);
//pictureBox1.Image = image;
/*
PictureBox pb = new PictureBox();
pb.Image = image;
pb.Dock = DockStyle.Fill;
 
this.Controls.Add(pb);
*/
/*

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));

this.pictureBox1.Image = (System.Drawing.Image)(resources.GetObject("ball1.gif"));
this.pictureBox1.Name = "pictureBox1";
//pictureBox1.Image = imgNumber;
*/
}

}
}

이게 디자이너 폼이 하나 더 있긴 한데 여기서
 

ArrayList al;
bool isStarted = false;
 쓰래드를 무슨 용도로 쓴것인지 궁금합니다 .. 
혹시나 아시는분 계신지요 ? ㅠ

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호