當前位置:編程學習大全網 - 源碼下載 - 用c shap編寫隨機點名的程序代碼

用c shap編寫隨機點名的程序代碼

Form1.Designer.cs的代碼:

namespace 隨機點名

{

partial class Form1

{

/// <summary>

/// 必需的設計器變量。

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// 清理所有正在使用的資源。

/// </summary>

/// <param name="disposing">如果應釋放托管資源,為 true;否則為 false。</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗體設計器生成的代碼

/// <summary>

/// 設計器支持所需的方法 - 不要

/// 使用代碼編輯器修改此方法的內容。

/// </summary>

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

this.button1 = new System.Windows.Forms.Button();

this.txt = new System.Windows.Forms.TextBox();

this.lbl = new System.Windows.Forms.Label();

this.lbl1 = new System.Windows.Forms.Label();

this.lbl2 = new System.Windows.Forms.Label();

this.button2 = new System.Windows.Forms.Button();

this.tm = new System.Windows.Forms.Timer(this.components);

this.richTextBox1 = new System.Windows.Forms.RichTextBox();

this.label1 = new System.Windows.Forms.Label();

this.SuspendLayout();

//

// button1

//

this.button1.Location = new System.Drawing.Point(171, 12);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 0;

this.button1.Text = "添加名單";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler(this.button1_Click);

//

// txt

//

this.txt.Location = new System.Drawing.Point(52, 12);

this.txt.Name = "txt";

this.txt.Size = new System.Drawing.Size(93, 21);

this.txt.TabIndex = 1;

//

// lbl

//

this.lbl.AutoSize = true;

this.lbl.BackColor = System.Drawing.Color.Lime;

this.lbl.Font = new System.Drawing.Font("楷體", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

this.lbl.ForeColor = System.Drawing.Color.Red;

this.lbl.Location = new System.Drawing.Point(234, 110);

this.lbl.Name = "lbl";

this.lbl.Size = new System.Drawing.Size(75, 20);

this.lbl.TabIndex = 2;

this.lbl.Text = "OOOOOO";

//

// lbl1

//

this.lbl1.AutoSize = true;

this.lbl1.BackColor = System.Drawing.SystemColors.Control;

this.lbl1.Font = new System.Drawing.Font("楷體", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

this.lbl1.Location = new System.Drawing.Point(234, 70);

this.lbl1.Name = "lbl1";

this.lbl1.Size = new System.Drawing.Size(75, 20);

this.lbl1.TabIndex = 3;

this.lbl1.Text = "OOOOOO";

//

// lbl2

//

this.lbl2.AutoSize = true;

this.lbl2.BackColor = System.Drawing.SystemColors.Control;

this.lbl2.Font = new System.Drawing.Font("楷體", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));

this.lbl2.Location = new System.Drawing.Point(234, 147);

this.lbl2.Name = "lbl2";

this.lbl2.Size = new System.Drawing.Size(75, 20);

this.lbl2.TabIndex = 4;

this.lbl2.Text = "OOOOOO";

//

// button2

//

this.button2.Location = new System.Drawing.Point(300, 214);

this.button2.Name = "button2";

this.button2.Size = new System.Drawing.Size(75, 23);

this.button2.TabIndex = 5;

this.button2.Text = "開始";

this.button2.UseVisualStyleBackColor = true;

this.button2.Click += new System.EventHandler(this.button2_Click);

//

// tm

//

this.tm.Tick += new System.EventHandler(this.tm_Tick);

//

// richTextBox1

//

this.richTextBox1.Location = new System.Drawing.Point(22, 55);

this.richTextBox1.Name = "richTextBox1";

this.richTextBox1.Size = new System.Drawing.Size(100, 140);

this.richTextBox1.TabIndex = 6;

this.richTextBox1.Text = "名單";

//

// label1

//

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(187, 117);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(41, 12);

this.label1.TabIndex = 7;

this.label1.Text = "中獎者";

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(410, 261);

this.Controls.Add(this.label1);

this.Controls.Add(this.richTextBox1);

this.Controls.Add(this.button2);

this.Controls.Add(this.lbl2);

this.Controls.Add(this.lbl1);

this.Controls.Add(this.lbl);

this.Controls.Add(this.txt);

this.Controls.Add(this.button1);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button button1;

private System.Windows.Forms.TextBox txt;

private System.Windows.Forms.Label lbl;

private System.Windows.Forms.Label lbl1;

private System.Windows.Forms.Label lbl2;

private System.Windows.Forms.Button button2;

private System.Windows.Forms.Timer tm;

private System.Windows.Forms.RichTextBox richTextBox1;

private System.Windows.Forms.Label label1;

}

}

Form1.cs的代碼:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace 隨機點名

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

String[] str=new String[100];

int n = 0;

private void button1_Click(object sender, EventArgs e)

{

if (String.IsNullOrEmpty(txt.Text)) {

MessageBox.Show("輸入為空!");

}

else {

str[n] = txt.Text;

richTextBox1.AppendText(str[n]+"\n");

MessageBox.Show("添加成功!");

n++;

}

}

int l = 0;

private void button2_Click(object sender, EventArgs e)

{

if (l == 0) {

tm.Start();

button2.Text = "停止";

l = 1;

}

else if (l == 1) {

tm.Stop();

button2.Text="開始";

l = 0;

}

}

static int k = 0;

private void tm_Tick(object sender, EventArgs e)

{

if (n < 3)

{ tm.Stop();

MessageBox.Show("名單太少,抽獎方式太浪費");

button2.Text = "開始";

}

else

{

if (k == 0) {

lbl1.Text = str[n-1];

lbl.Text = str[k];

lbl2.Text = str[k+1];

k++;

}

else if (k >0&&k<n-1 )

{

lbl1.Text = str[k-1];

lbl.Text = str[k];

lbl2.Text = str[k+1 ];

k++;

}

else {

lbl.Text = str[k];

lbl1.Text = str[n-2];

lbl2.Text = str[0];

k = 0;

}

}

}

private void Form1_Load(object sender, EventArgs e)

{

richTextBox1.AppendText("\n");

}

}

}

Program.cs的代碼:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace 隨機點名

{

static class Program

{

/// <summary>

/// 應用程序的主入口點。

/// </summary>

[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new Form1());

}

}

}

////給分吧,我的q2472591219,若需要加我,我將實例打包給妳

  • 上一篇:短線期貨要看什麽指標?
  • 下一篇:dlopen和System.loadLibrary的區別
  • copyright 2024編程學習大全網