开发者

how to make best player screen? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜