Search
DiagramView.PaintControl Event
See Also
 





Raised when a hosted control must be printed, drawn in a print-preview or Overview window, or drawn in an exported bitmap.

Namespace: MindFusion.Diagramming.WinForms
Assembly: MindFusion.Diagramming.WinForms

 Syntax

C#  Copy Code

public event EventHandler<PaintControlEventArgs> PaintControl

Visual Basic  Copy Code

Public Event PaintControl As EventHandler(Of PaintControlEventArgs)

 Event Data

PaintControl event handlers receive an argument of type PaintControlEventArgs. The following PaintControlEventArgs members provide information relevant to the event:

Member name

Description

Node

The ControlNode whose hosted control should be custom-drawn.

PaintRect

The bounding rectangle of the hosted control.

Handled

Set this flag to true if you have custom-drawn the control.

Graphics

An object implementing the IGraphics interface whose methods should be used to draw the control.

 Remarks

This event is raised when a control hosted inside a ControlNode must be painted off screen. When MindFusion.Diagramming displays a diagram on the screen, hosted controls have their own windows in which they paint themselves. However, when printing diagrams, exporting them to image files or displaying them in overview or print preview windows, hosted controls cannot be always painted by MindFusion.Diagramming.

By handling PaintControl, your application can provide own rendering of the control's data. That is done by painting in the rectangle specified in PaintRect argument by means of the methods of the Graphics argument.

If that event is not handled, MindFusion.Diagramming invokes the OnPaint method of the hosted System.Windows.Forms.Control instance. However, not all controls do their painting in OnPaint; for example, some are mere wrappers of Windows common controls and their OnPaint implementation is empty.

 Example

The following example shows how to handle the event for hosted TextBox controls:

C#  Copy Code

void diagramView_PaintControl(object sender, PaintControlEventArgs e)
{
    // If we host TextBox controls, paint a close representation of their
    // contents when rendering to printer/preview/overview and so on
    if (e.Node.Control is TextBox)
    {
        TextBox tb = (TextBox)e.Node.Control;

        System.Drawing.Brush wb = new System.Drawing.SolidBrush(Color.Blue);
        e.Graphics.FillRectangle(wb, e.PaintRect);
        wb.Dispose();

        // Now you can't distinguish that from a real TextBox
        System.Drawing.Brush bb = new System.Drawing.SolidBrush(Color.Black);
        Font font = new Font("Arial", 2, GraphicsUnit.World);

        e.Graphics.DrawString(tb.Text, font, bb, e.PaintRect);

        font.Dispose();
        bb.Dispose();
    }
}

Visual Basic  Copy Code

Private Sub diagramView_PaintControl(ByVal sender As Object, ByVal e As PaintControlEventArgs) Handles diagramView.PaintControl

    ' If we host TextBox controls, paint a close representation of their
    ' contents when rendering to printer/preview/overview and so on
    If TypeOf e.Node.Control Is TextBox Then

        Dim tb As TextBox = CType(e.Node.Control, TextBox)

        Dim wb As New System.Drawing.SolidBrush(Color.Blue)
        e.Graphics.FillRectangle(wb, e.PaintRect)
        wb.Dispose()

        ' Now you can't distinguish that from a real TextBox
        Dim bb As New System.Drawing.SolidBrush(Color.Black)
        Dim font As New Font("Arial", 2, GraphicsUnit.World)

        e.Graphics.DrawString(tb.Text, font, bb, e.PaintRect)

        font.Dispose()
        bb.Dispose()

    End If

End Sub

 See Also