[英]Creating a leaderboard using TableLayoutPanel
Visual C#。 尋找一種遍歷TableLayoutPanel的標簽以顯示用戶名和得分的方法。 該列表按分數按降序排序。
label1.Text = SortedList[0].Username; label2.Text = Convert.ToString(SortedList[0].Score);
label3.Text = SortedList[1].Username; label4.Text = Convert.ToString(SortedList[1].Score);
label5.Text = SortedList[2].Username; label6.Text = Convert.ToString(SortedList[2].Score);
//Continues until I have 10 rows.
我這樣寫是為了表明每一行都是一行。 我希望這使我在這里想要實現的目標更加明確。
我會做這樣的事情:(對不起,自從我完成WinForms以來已經有一段時間了)
var userNameLabels = Label[10]{label1, label3, label5,....}
var userScocreLabels = Label[10]{label2, label4, label6,....}
for(int i = 0; i <= SortedList.Count(); i++){
userNameLabels[i].Text = SortedList[i].Username;
userScocreLabels[i].Text = SortedList[i].Score.ToString();
}
我認為適合這項工作的工具是DataGridView
//below property is true by default - will generate columns for properties automatically
yourDataGridView.AutoGenerateColumns = true;
yourDataGridView.DataSource = SortedList;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.