我正在製作一個ATM模擬器,並且我正在嘗試在一個表單上創建另一個表單(ATM)的按鈕。我已經能夠做到這一點,但只適用於一種形式,因爲當新的表單出現時,我無法點擊其他具有「添加atm」按鈕的表單。我試過使用C#的Form.Show
,Form.ShowDialog
和Applications.Run()
。當出現新表單時,無法點擊其他表單C#
這裏是代碼:
public class Program
{
private Account[] ac = new Account[3];
private ATM atm;
public Form1 form1;
/* This function initilises the 3 accounts
* and instanciates the ATM class passing a referance to the account information
*/
public Program()
{
ac[0] = new Account(300, 1111, 111111);
ac[1] = new Account(750, 2222, 222222);
ac[2] = new Account(3000, 3333, 333333);
Thread form1thread = new Thread(new ThreadStart(startform)); //Creates ATM Form
//Thread atm2 = new Thread(new ThreadStart(start));
form1thread.Start();
//atm2.Start();
}
static void Main(string[] args)
{
new Program();
}
public void startform()
{
form1 = new Form1(this);
form1.ShowDialog();
}
public void newatm()
{
atm = new ATM(ac);
atm.ShowDialog();
}
public void makethread()
{
Thread newatm = new Thread(new ThreadStart(startform));
newatm.Start();
}
}
,並在Form1:
public partial class Form1 : Form
{
Program program;
public Form1(Program program)
{
InitializeComponent();
this.program = program;
}
private void Form1_Load(object sender, EventArgs e)
{
this.ShowDialog();
}
private void button1_Click(object sender, EventArgs e)
{
program.newatm();
}
}
也許是因爲你在代碼中的某個地方做ShowModal ..你能顯示你正在使用的代碼,這樣我們可以限制所有的猜測工作..? – MethodMan 2013-03-18 20:04:46
你使用Windows Forms還是WPF? – user1166905 2013-03-18 20:05:37