Winform random roll call

Click randomly selected, lable1 change the name of a class of persons.

code show as below:

1. declare an array, which carried the name of store personnel.

        string [] names = { "John Doe", "John Doe", "Wang Wu", "Liang", "Zhang", "Guan Yu", "Bai", "Zhang Liang", "Jing Ke", "Bu" };

2. Set the timer timer controls how often were carried out to extract the names of personnel.  

  void the Form1_Load Private (SENDER Object, EventArgs E)
  {
    // name display speed
    Timer1.Interval = 10;
  }

3. Click the button

  void the button2_Click Private (SENDER Object, EventArgs E)
  {
    // Start or pause timer1
    Timer1.Enabled = button2.Text == "start" to true:? false;
    // Modify button text
    button2.Text = button2.Text == "start "?" pause ":" start ";
  }

4. Display the name of the person in the timer click event

  void the timer1_Tick Private (SENDER Object, EventArgs E)
  {
    // display a random name
    Label1.Text names = [new new the Random () the Next (0, names.length).];
  }

 

In this way, you can complete a simple random named a. . . . . . .

Guess you like

Origin www.cnblogs.com/LLF123/p/11431461.html