随机数演示(窗体应用程序)
生活随笔
收集整理的這篇文章主要介紹了
随机数演示(窗体应用程序)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
新建窗體應用程序(如下),新建控件label1,label2,label3,label4,label5,textBOX1,textBOX2,button1,button2
label1的Text屬性改為“隨機數演示”
label2的Text屬性改為“最大值”
label3的Text屬性改為“最小值”
label4的Text屬性改為“生成隨機數”
button1的Text屬性改為“確定”
button1的Text屬性改為“退出”
完整代碼:
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Threading.Tasks; 9 using System.Windows.Forms; 10 11 namespace WindowsFormsApplication2 12 { 13 public partial class Form1 : Form 14 { 15 public Form1() 16 { 17 InitializeComponent(); 18 } 19 20 private void button1_Click(object sender, EventArgs e)//確定按鈕代碼 21 { 22 try 23 { 24 int num1 = Convert.ToInt32(textBox1.Text); 25 int num2 = Convert.ToInt32(textBox2.Text); 26 Random r = new Random(); 27 int i = r.Next(num2, num1+1); 28 label5.Text = Convert.ToString(i); 29 } 30 catch 31 { 32 MessageBox.Show("請輸入整數"); 33 } 34 } 35 36 private void button2_Click(object sender, EventArgs e)//退出按鈕代碼 37 { 38 Application.Exit(); 39 } 40 } 41 }?
轉載于:https://www.cnblogs.com/start-from-scratch/p/5044771.html
總結
以上是生活随笔為你收集整理的随机数演示(窗体应用程序)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: json数组传递到后台controlle
- 下一篇: 树莓派利用PuTTY进行远程登录