public void FitFont() { if (ParentForm == null) { return; } float w = ClientRectangle.Width - 15; float h = ClientRectangle.Height; float size = smallFont.Size; Graphics g = ParentForm.CreateGraphics(); if (orientation == OrientationType.Horizontal) { float baseH = g.MeasureString("123", smallFont).Height; if (baseH > h / 1.5) { do { size--; smallFont = new Font("Calibri", size, FontStyle.Bold); baseH = g.MeasureString("123", smallFont).Height; } while (baseH > h / 1.5); } else { do { size++; smallFont = new Font("Calibri", size, FontStyle.Bold); baseH = g.MeasureString("123", smallFont).Height; } while (baseH < h / 1.5); } } else { float baseW = g.MeasureString("12345", smallFont).Width; if (baseW > w) { do { size--; smallFont = new Font("Calibri", size, FontStyle.Bold); baseW = g.MeasureString("1235", smallFont).Width; } while (baseW > w); } else { do { size++; smallFont = new Font("Calibri", size, FontStyle.Bold); baseW = g.MeasureString("1235", smallFont).Width; } while (baseW < w); } } }
public override void Draw() { using (Graphics graphics = ParentForm.CreateGraphics()) { _drawingMachine.DrawBoard(graphics, new Size(ParentForm.FormWidth, ParentForm.FomrHeight), _board); graphics.Dispose(); } }
public override void Draw() { Bitmap backbuffer = new Bitmap(Constants.CanvasWidth, Constants.CanvasWidth); using (Graphics graphics = Graphics.FromImage(backbuffer)) { ClearTheCanvas(graphics); DrawShips(graphics); DrawPhotons(graphics); DrawMeteors(graphics); DrawHeadsUpDisplay(graphics); _enemyShipShooterService.Draw(graphics); _scorePointsDisplay.Draw(graphics); } //Draw onto the window using (Graphics windowGraphics = ParentForm.CreateGraphics()) { windowGraphics.DrawImageUnscaled(backbuffer, 0, 0); } }