cevik123123
Member
- Joined
- Oct 28, 2018
- Messages
- 6
- Programming Experience
- Beginner
Hello , i am making a little game but i cant locate my buttons randomly is there any advice for me ?
i just made some buttons but i cant make them random.
i try something like this but i cant reach the solution.
i am trying to show the button's text random its hasn't to be location but i cant find anything to solve this problem.
i hope someone has some solve for this problem. Thanks a lot.
C#:
[COLOR=#0000ff][B]public[/B][/COLOR] [COLOR=#004085]Orta[/COLOR]()
{
[COLOR=#008000]//[/COLOR]
[COLOR=#008000]// The InitializeComponent() call is required for Windows Forms designer support.[/COLOR]
[COLOR=#008000]//[/COLOR]
[COLOR=#191970][B]InitializeComponent[/B][/COLOR]();
[COLOR=#0000ff][B]for[/B][/COLOR] ([COLOR=#ff0000][B]int[/B][/COLOR] i = [COLOR=#00008b]0[/COLOR]; i < [COLOR=#00008b]40[/COLOR]; i++) {
[COLOR=#004085]Button[/COLOR] buton = [COLOR=#008b8b][B]new[/B][/COLOR] [COLOR=#004085]Button[/COLOR] {
Name = [COLOR=#0000ff]"buton"[/COLOR]+i,
Text = (i+[COLOR=#00008b]1[/COLOR]).[COLOR=#191970][B]ToString[/B][/COLOR](),
Height = [COLOR=#00008b]50[/COLOR],
Width = [COLOR=#00008b]50[/COLOR],
};
[I]flowLayoutPanel1[/I].Controls.[COLOR=#191970][B]Add[/B][/COLOR](buton);
}
[COLOR=#008000]//[/COLOR]
[COLOR=#008000]// [COLOR=#ff0000][B]TODO[/B][/COLOR]: Add constructor code after the InitializeComponent() call.[/COLOR]
[COLOR=#008000]//[/COLOR]
}
C#:
[COLOR=#0000FF][B]for[/B][/COLOR] ([COLOR=#FF0000][B]int[/B][/COLOR] i = [COLOR=#00008B]0[/COLOR]; i < [COLOR=#00008B]40[/COLOR]; i++) {
Random rnd = new Random();
[COLOR=#004085]Button[/COLOR] buton = [COLOR=#008B8B][B]new[/B][/COLOR] [COLOR=#004085]Button[/COLOR] {
Name = [COLOR=#0000FF]"buton"[/COLOR]+i,
Location = new Point(rnd.Next(1,40)), // this is not working.
Text = (i+[COLOR=#00008B]1[/COLOR]).[COLOR=#191970][B]ToString[/B][/COLOR](),
Height = [COLOR=#00008B]50[/COLOR],
Width = [COLOR=#00008B]50[/COLOR],
};
[I]flowLayoutPanel1[/I].Controls.[COLOR=#191970][B]Add[/B][/COLOR](buton);
}
i am trying to show the button's text random its hasn't to be location but i cant find anything to solve this problem.
i hope someone has some solve for this problem. Thanks a lot.