用c shap编写随机点名的程序代码

用c shap编写随机点名的程序代码,第1张

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,若需要加我,我将实例打包给你

excel的随机点名的设置步骤如下:

1、首先我们打开电脑里的excel软件,在A列单元格里输入同学们的姓名,我这里为方便用百度+数字来表示。

2、然后我们在另外的单元格先输入函数  =INDIRECT("a")  。

3、然后我们继续输入完整的函数,即“=INDIRECT("a"&RANDBETWEEN(2,16))”表示从A列第2-16单元格里随机选择一个单元格数据。

4、然后我们选中A列。

5、点击右键,点击隐藏,将名字隐藏起来,或许也可以省略这一步。

6、点名的时候只需要一直按住F9即可,松开时,就会出现一个名字了。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7868038.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存