static void addScore(HighScore h) { using (var db = new ScoreDbContext()) { db.HighScores.Add(h); db.SaveChanges(); } }
public void ScorePanelShow() { Label ScoreTitle = new Label(); Button Menu = new Button(); Button Start = new Button(); ListView scoreList = new ListView(); ScorePanel.Size = new Size(784, 561); ScorePanel.Location = new Point(0, 0); ScorePanel.BackColor = System.Drawing.Color.Black; ScoreTitle.Text = "High Scores"; ScoreTitle.Location = new Point(200, 100); ScoreTitle.ForeColor = System.Drawing.Color.White; ScoreTitle.Size = new Size(400, 55); ScoreTitle.Font = new Font("Microsoft Sans Serif", 36, FontStyle.Bold); Start.Location = new Point(700, 0); Start.BackColor = System.Drawing.Color.AliceBlue; Start.Text = "Start"; Start.Click += button1_Click; Menu.Location = new Point(0, 0); Menu.BackColor = System.Drawing.Color.AliceBlue; Menu.Text = "Menu"; Menu.Click += Menu_Click; using (var db = new ScoreDbContext()) { HighScoreList = db.HighScores.ToList(); } HighScoreList.ForEach(h => scoreList.Items.Add(h.Name + " " + h.Score, h.ID)); scoreList.Location = new Point(200, 220); scoreList.Size = new Size(400, 200); this.Controls.Add(ScorePanel); ScorePanel.Show(); ScorePanel.BringToFront(); ScorePanel.Controls.Add(ScoreTitle); ScorePanel.Controls.Add(Start); ScorePanel.Controls.Add(Menu); ScorePanel.Controls.Add(scoreList); }