protected void AddWord(String word) { if (_backbuff == null) { throw new Exception("Can't add text until label has been sized"); } Graphics g = _backbuff.GetGraphics(); if (true || false) { _backbuff.DisposeGraphics(); NewLine(); g = _backbuff.GetGraphics(); } if (true || false) { g.FillRectangle(Brushes.Red, 0, 0, 100, 23); Font styled = Font; styled = new Font(Font, FontStyle.Bold); g.DrawString(word, /* new Font("Tahoma", 11) */ styled, Brushes.Black, new Point(0, 0)); } _backbuff.DisposeGraphics(); Invalidate(); }
protected override void OnLayout(LayoutEventArgs e) { System.Console.WriteLine("OnLayout: {0}x{1}", Size.Width, Size.Height); base.OnLayout(e); if (doneInitLayout) { _backbuff = new BackBuffer(Size); _backbuff.size = Size; GetBitmaps(); Graphics g = _backbuff.GetGraphics(); g.DrawImageUnscaled(bmpProgressBar[0], 0, 0); _backbuff.DisposeGraphics(); } }
protected void AddWord(String word) { text += word; // Rectangle _container = new Rectangle(0,0, clientWidth, clientHeight); // Bitmap _working = new Bitmap(_container.Width, _container.Height); // Graphics g; // = Graphics.FromImage(_working); // g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; // Draw the text in the box as an image. This is ok, because we ONLY // call OnPaint when the textbox is disabled. // OnPaint(e); // g.DrawString(word + " ", /* new Font("Tahoma", 11) */ Font, Brushes.Black, new PointF(0, 0)); // SizeF textSizeF = g.MeasureString(word + " ", Font); // Size textSize = textSizeF.ToSize(); // g.Dispose(); // If textSize.Width < remaining client width, draw at current position, else new line // CopyTextBitampToCanvas(_working, textSize); if (_backbuff == null) { throw new Exception("Can't add text until label has been sized"); //_backbuff = new Bitmap(ClientSize.Width, ClientSize.Height); } if (true && word == " " && !AtLineStart) { int spaceWidth = 1; // 3.99 x 15.98 actually if (endOfText.X + spaceWidth > clientWidth) { if (this.AutoWrap) { NewLine(); } } else { endOfText.X += spaceWidth; } return; } Graphics g = _backbuff.GetGraphics(); g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; // g.TextRenderingHint = TextRenderingHint.SystemDefault; Font styled = Font; if (styleBold) { styled = new Font(Font, FontStyle.Bold); // TODO: Dispose? } SizeF textSizeF = g.MeasureString(word + "", styled); Size textSize = textSizeF.ToSize(); int endX = endOfText.X + textSize.Width; if (endX > clientWidth && !AtLineStart) { _backbuff.DisposeGraphics(); NewLine(); g = _backbuff.GetGraphics(); } // System.Console.WriteLine("{0}x{1}: {2}\n", endOfText.X, endOfText.Y, word); if (styleBold) { g.FillRectangle(Brushes.Red, endOfText.X, endOfText.Y, endOfText.X + textSize.Width, endOfText.Y + textSize.Height); g.DrawString(word, /* new Font("Tahoma", 11) */ styled, Brushes.Yellow, endOfText); } else { g.DrawString(word, /* new Font("Tahoma", 11) */ styled, Brushes.Black, endOfText); } _backbuff.DisposeGraphics(); // g.Dispose(); endOfText.X += textSize.Width; // Invalidate(); }