how to make best player screen? [closed]
i am using visual studio 2008 c# winform. . i've make sudoku game which is working well . . i want to make best player screen for it and score depend on how much time the player take to complete game . . i am using another form to take player name when he meets the condition for best player and give the name to label on main开发者_开发百科 form but its not working.here is my code:
private void button1_Click(object sender, EventArgs e)
{
Form1 main = new Form1();
main.lbBEN.Text = textBox1.Text;
this.Close();
}
and this on another form:
if (emint<bmint)
{
best b = new best();
b.ShowDialog();
}
please guide me. . .THANK you
Add a public property to the second form and just below the ShowDialog(), sets the form1 label.Text to that property containing the name of the user.
public partial class Form2 : Form
{
string _highestScoreUser = string.Empty;
public Form2()
{
}
public string HighestScoreUser
{
get{ return _highestScoreUser; }
set{ _highestScoreUser = value; }
}
}
In Form1 code after ShowDialog is called like
{
Form2 form = new Form2();
form.ShowDialog();
form1.label.Text = form.HighestScoreUser;
}
Hope this help
You've created a brand new Form1
object unrelated to the Form1
that is already on the screen. You need to somehow pass a reference to the real Form1
the the secondary form.
精彩评论