//Add player to list private async void btnAdd_Click(object sender, EventArgs e) { var x = new FormAddPlayer(StyleManager); if (x.ShowDialog() == DialogResult.OK) { mgTable.Rows.Add(); int rows = mgTable.Rows.Count; mgTable[1, rows - 2].Value = x.PlayerName; mgTable[2, rows - 2].Value = x.PurchasePrice; mgTable[3, rows - 2].Value = x.SellPrice; mgTable[4, rows - 2].Value = 0; //Counter mgTable[5, rows - 2].Value = x.Rarity; mgTable[6, rows - 2].Value = x.Rating; mgTable[7, rows - 2].Value = x.Position; mgTable[8, rows - 2].Value = x.Id; mgTable[9, rows - 2].Value = x.ImgUrl; try { var reqImg = (HttpWebRequest)WebRequest.Create(x.ImgUrl); reqImg.Method = "GET"; var respImg = await reqImg.GetResponseAsync(); if (respImg != null) { // ReSharper disable once AssignNullToNotNullAttribute Bitmap bmp = new Bitmap(stream: respImg.GetResponseStream()); respImg.Close(); mgTable[0, rows - 2].Value = bmp; } } catch (Exception) { tbLog.SelectionColor = Color.Red; tbLog.SelectedText = "Error getting Image" + Environment.NewLine; } } x.Dispose(); }
//Add player to list private async void btnAdd_Click(object sender, EventArgs e) { var x = new FormAddPlayer(); if (x.ShowDialog() == DialogResult.OK) { mgTable.Rows.Add(); int rows = mgTable.Rows.Count; mgTable[1, rows - 2].Value = x.PlayerName; try { mgTable[2, rows - 2].Value = RoundPrices.RoundToFinal(uint.Parse(x.PurchasePrice)); mgTable[3, rows - 2].Value = RoundPrices.RoundToFinal(uint.Parse(x.SellPrice)); } catch { } mgTable[4, rows - 2].Value = 0; //Counter mgTable[5, rows - 2].Value = x.Rarity; mgTable[6, rows - 2].Value = x.Rating; mgTable[7, rows - 2].Value = x.Position; mgTable[8, rows - 2].Value = x.Id; mgTable[9, rows - 2].Value = x.ImgUrl; try { var reqImg = (HttpWebRequest)WebRequest.Create(x.ImgUrl); reqImg.Method = "GET"; var respImg = await reqImg.GetResponseAsync(); if (respImg != null) { // ReSharper disable once AssignNullToNotNullAttribute Bitmap bmp = new Bitmap(stream: respImg.GetResponseStream()); respImg.Close(); mgTable[0, rows - 2].Value = bmp; } } catch (Exception) { tbLog.SelectionColor = Color.Red; tbLog.SelectedText = "Error getting Image" + Environment.NewLine; } } x.Dispose(); }