protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Visible) { //Deferred text rendering (first render) if (_hText == null) { _hText = ThemedText.Create(e.Graphics, Text, Font, Padding, new Rectangle(0, 0, Size.Width, Size.Height), ForeColor, CreateFormatFlags(), CreateOptions()); } if (_needsUpdate) { //Draw (avoids flickering because of delayed redraw) _hText.Draw(e.Graphics, new Rectangle(0, 0, Size.Width, Size.Height)); //Redraw the text element _hText.Update(e.Graphics, Text, Font, Padding, new Rectangle(0, 0, Size.Width, Size.Height), ForeColor, CreateFormatFlags(), CreateOptions()); //Signal update as done, and then redraw again with updated graphics _needsUpdate = false; this.Invalidate(); } else { //Simply redraw _hText.Draw(e.Graphics, new Rectangle(0, 0, Size.Width, Size.Height)); } } }
protected override void OnHandleDestroyed(EventArgs e) { //Clean up if (_hText != null) { _hText.Dispose(); } _hText = null; base.OnHandleDestroyed(e); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (Visible) { //Deferred text rendering (first render) if (_hText == null) _hText = ThemedText.Create(e.Graphics, Text, Font, Padding, new Rectangle(0, 0, Size.Width, Size.Height), ForeColor, CreateFormatFlags(), CreateOptions()); if (_needsUpdate) { //Draw (avoids flickering because of delayed redraw) _hText.Draw(e.Graphics, new Rectangle(0, 0, Size.Width, Size.Height)); //Redraw the text element _hText.Update(e.Graphics, Text, Font, Padding, new Rectangle(0, 0, Size.Width, Size.Height), ForeColor, CreateFormatFlags(), CreateOptions()); //Signal update as done, and then redraw again with updated graphics _needsUpdate = false; this.Invalidate(); } else { //Simply redraw _hText.Draw(e.Graphics, new Rectangle(0, 0, Size.Width, Size.Height)); } } }
protected override void OnHandleDestroyed(EventArgs e) { //Clean up if (_hText != null) _hText.Dispose(); _hText = null; base.OnHandleDestroyed(e); }