I'm coding a simple game (pick-up sticks) to get use to coding. Once you click begin, I have a popup Form that allows you to select the computer type (Basically type 1, 2, or 3). I open the second Form in a new thread and keep the first thread paused until the second is closed.
namespace Sticks
{
public partial class guiMain : Form
{
//Set Public Namespace Variables
public int compType = 0; //1=timid 2=greedy 3=smart
public guiMain()
{
InitializeComponent();
}
private void btnBegin_Click(object sender, EventArgs e)
{
btnHelp.Enabled = false;
btnBegin.Enabled = false;
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));
t.Start();
this.Invoke((MethodInvoker)delegate { label2.Text = "Test"; });
while (t.IsAlive)
{
Thread.Sleep(100);
this.Refresh();
}
}
}
}
The second Form contains buttons that are suppose to be able to set compType variable but I don't know how to update it from a Form on another Thread.
namespace Sticks
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//set compType to 1
Close();
}
private void button2_Click(object sender, EventArgs e)
{
//set compType to 2
Close();
}
private void button3_Click(object sender, EventArgs e)
{
//set compType to 3
Close();
}
}
}
Now remember, I'm still starting out. I am using Microsoft Visual C# 2010 Express for my coding. I have Google this issue but only came up solutions that I did not understand how to implement. Thanks in advanced!

New Topic/Question
Reply



MultiQuote





|