看板 C_Sharp 關於我們 聯絡資訊
※ 引述《piyet (小丸)》之銘言: : 我寫了一個程式有十個button每個button點下去後都會出現一個亂數, : 然後那個亂數值會傳到一個textBox中, : 目前我是做了一個textBox1,所以button的值都會跑到textBox1中, : 可是我想要做兩個textBox, : 讓第一個亂數值傳到textBox1中,第二個亂數值跑到textBox2中, : 要怎麼解決呢?? 不知道你這邊貼3個button程式碼的意思@@? random rs=new random(); 這邊是把亂數種子排列 int a =rs.next(6); 產生一個0~5以內的任意整數 如果是把它填入第一個textbox. 就把它textbox1.text=a.tostring(). 這樣 然後接著就產生第二個亂數 a=rs.next(6); textbox2.text=a.tosting() 這樣就可以了. 不過我會寫成 textbox1.text=rs.next(6).tostring(); textbox2.text=rs.next(6).tostring(); 你就把他想成一個按鈕產生兩個不同的亂數 分別填入不同的textbox. 這樣就好了. -- : private void button1_Click(object sender, EventArgs e) : { : Random rs = new Random(); : int a = rs.Next(6); // int 0-6亂數 : button1.Text = a.ToString(); : textBox1.text += button1.Text; : } : private void button2_Click(object sender, EventArgs e) : { : Random rs = new Random(); : int a = rs.Next(6); // int 0-6亂數 : button2.Text = a.ToString(); : textBox1.Text += button2.Text; : } : private void button3_Click(object sender, EventArgs e) : { : Random rs = new Random(); : int a = rs.Next(6); // int 0-6亂數 : button3.Text = a.ToString(); : textBox1.Text += button3.Text; : } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.169.233.230