private static void SetLabelTextAndWidth(Label label, UserControl parent, string text, int padding) { label.Text = text; using (Graphics g = parent.CreateGraphics()) { label.Width = ((int)g.MeasureString(label.Text, label.Font).Width) + padding; } }
static void Update() { var g = table.CreateGraphics(); g.Clear(Color.White); var W = table.ClientSize.Width / baseMaker.OutputSize; var H = table.ClientSize.Height / baseMaker.OutputSize; for (int i = 0; i < baseMaker.OutputSize; i++) { for (int j = 0; j < baseMaker.OutputSize; j++) { var p = (int)(percentage[i, j] * 255); var color = Color.FromArgb(255, 255 - p, 255 - p); if (i == j) { color = Color.FromArgb(255 - p, 255, 255 - p); } g.FillRectangle( new SolidBrush(color), W * i, H * j, W, H); if (i == j) { g.DrawString( baseMaker.Symbols[i].ToString(), baseMaker.Font, percentage[i, i] > 0.5?Brushes.White:Brushes.Black, new Rectangle(W * i, H * j, W, H), new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } } } success.AddRange(new[] { totalErrors }); }
//protected override void OnPaint(PaintEventArgs e) //{ // base.OnPaint(e); // DrawDamier(e.Graphics, simulation.usa.GetPlateauDeJeuDame()); //} private void DrawDamierInital(UserControl graph, List <ZonePion> plateau) { foreach (var zone in plateau) { rec.Height = 55; rec.Width = 55; rec.X = zone.X * rec.Height; rec.Y = zone.Y * rec.Width; Pen peno = new Pen(Color.Black); using (Graphics g = graph.CreateGraphics()) { if (rec.X % 2 == 0) { if (rec.Y % 2 == 0) { Brush brush = Brushes.White; g.DrawRectangle(peno, rec); g.FillRectangle(brush, rec); if (zone.Occupe == true && zone.PionPosseder.Equals("PionBlanc")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\white.png"), rec); } else if (zone.Occupe == true && zone.PionPosseder.Equals("PionNoir")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\black.png"), rec); } } else { Brush brush = Brushes.Turquoise; g.DrawRectangle(peno, rec); g.FillRectangle(brush, rec); if (zone.Occupe == true && zone.PionPosseder.Equals("PionNoir")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\black.png"), rec); } else if (zone.Occupe == true && zone.PionPosseder.Equals("PionBlanc")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\white.png"), rec); } } } else { if (rec.Y % 2 == 0) { Brush brush = Brushes.Turquoise; Brush balck = Brushes.Black; g.DrawRectangle(peno, rec); g.FillRectangle(brush, rec); if (zone.Occupe == true && zone.PionPosseder.Equals("PionNoir")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\black.png"), rec); } else if (zone.Occupe == true && zone.PionPosseder.Equals("PionBlanc")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\white.png"), rec); } } else { Brush brush = Brushes.White; g.DrawRectangle(peno, rec); g.FillRectangle(brush, rec); if (zone.Occupe == true && zone.PionPosseder.Equals("PionBlanc")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\white.png"), rec); } else if (zone.Occupe == true && zone.PionPosseder.Equals("PionNoir")) { g.DrawImage(Image.FromFile(@"C:\Users\" + Environment.UserName + @"\Documents\GitHub\DesignPatternSimulator\DesignPatternSimulator\designpattern\strategie\personnage\pictures\black.png"), rec); } } } } } }