/// <summary> /// Performs the element post-children custom paint. Overriden to paint the status /// of this example tile (if it has one) in its bottom-left corner. /// </summary> /// <param name="visitor"></param> protected override void OnPostPaint(NPaintVisitor visitor) { base.OnPostPaint(visitor); if (String.IsNullOrEmpty(m_Status)) { return; } // Paint a new label in the bottom left corner NRectangle bounds = GetContentEdge(); NFont font = new NFont(FontName, 5.0, ENFontStyle.Regular); font.RasterizationMode = ENFontRasterizationMode.Aliased; NSize textSize = font.MeasureString(m_Status, this.OwnerDocument); NRectangle textRect = new NRectangle(bounds.X - 1, bounds.Bottom - textSize.Height, textSize.Width + 3, textSize.Height); // Paint the text background NColor color = HomePage.GetStatusColor(m_Status); visitor.SetFill(color); visitor.PaintRectangle(textRect); // Paint the text visitor.SetFill(NColor.White); visitor.SetFont(font); NPoint location = textRect.Location; NPaintTextPointSettings settings = new NPaintTextPointSettings(); visitor.PaintString(location, m_Status, ref settings); }
/// <summary> /// /// </summary> /// <param name="args"></param> private void OnCanvasPrePaint(NCanvasPaintEventArgs args) { NCanvas canvas = args.TargetNode as NCanvas; if (canvas == null) { return; } NPaintVisitor paintVisitor = args.PaintVisitor; NRectangle contentEge = canvas.GetContentEdge(); // create the settings NPaintTextRectSettings settings = new NPaintTextRectSettings(); settings.SingleLine = false; settings.WrapMode = ENTextWrapMode.WordWrap; settings.HorzAlign = ENTextHorzAlign.Left; settings.VertAlign = ENTextVertAlign.Top; // create the text string text = m_TextBox.Text; // calculate the text bounds the text bounds double resolution = canvas.OwnerDocument.GetEffectiveResolution(); NFont font = new NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Regular); NSize textSize = font.MeasureString(text.ToCharArray(), resolution, contentEge.Width, false, ref settings); NPoint center = contentEge.Center; NRectangle textBounds = new NRectangle( center.X - textSize.Width / 2.0, center.Y - textSize.Height / 2.0, textSize.Width, textSize.Height); // paint the bounding box paintVisitor.ClearStyles(); paintVisitor.SetFill(NColor.LightBlue); paintVisitor.PaintRectangle(textBounds); // init font and fill paintVisitor.SetFill(NColor.Black); paintVisitor.SetFont(font); // paint the text paintVisitor.PaintString(textBounds, text.ToCharArray(), ref settings); }