Nevron Forum

Draw Diagram on an Existing User Control

https://www.nevron.com/Forum/Topic6864.aspx

By Joe Marino - Thursday, August 23, 2012

Is it possible to draw a diagram onto an existing user control?

I want to have the user interact with a diagram over a video control.

 

 

Thank You

By Nevron Support - Thursday, August 23, 2012

Hi Joe,

Following is a drawing view subclass, that should be transparent:

public class NMyDrawingView : NDrawingView
{
    public NMyDrawingView()
    {
        //Set the default backcolor
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        this.BackColor = Color.Transparent;
    }
    public override void DoPaint(PaintEventArgs e)
    {
        if (Document == null)
        {
            if (DesignMode)
            {
                PaintEmptyInDesignMode(e);
            }

            return;
        }

        if (LockRefresh)
            return;

        GraphicsState state;
        NPaintContext context;

        try
        {
            //e.Graphics.Clear(WindowBackColor);

            if (NeedsWindowBackgroundPaint(e))
            {
                state = e.Graphics.Save();
                context = ProvideViewPaintContext(e, PaintPass.Background);
                PaintWindowBackground(context);
                e.Graphics.Restore(state);
            }

            if (NeedsDocumentBackgroundPaint(e))
            {
                state = e.Graphics.Save();
                context = ProvideDocumentPaintContext(e, PaintPass.Background);
                PaintDocumentBackground(context);
                e.Graphics.Restore(state);
            }

            if (NeedsViewBackgroundPaint(e))
            {
                state = e.Graphics.Save();
                context = ProvideViewPaintContext(e, PaintPass.Background);
                PaintViewBackground(context);
                e.Graphics.Restore(state);
            }

            if (NeedsDocumentForegroundPaint(e))
            {
                state = e.Graphics.Save();
                context = ProvideDocumentPaintContext(e, PaintPass.Foreground);
                PaintDocumentForeground(context);
                e.Graphics.Restore(state);
            }

            if (NeedsViewForegroundPaint(e))
            {
                state = e.Graphics.Save();
                context = ProvideViewPaintContext(e, PaintPass.Foreground);
                PaintViewForeground(context);
                e.Graphics.Restore(state);
            }
        }
        catch (Exception ex)
        {
            Trace.WriteLine("Drawing view paint failed. Exception info follows: ");
            Trace.WriteLine("------------------------------------");
            Trace.WriteLine(" Message: " + ex.Message);
            Trace.WriteLine(" Stack Trace: " + ex.StackTrace);
            Trace.WriteLine("------------------------------------");
        }

        if (SmartPaintService != null)
        {
            SmartPaintService.Reset();
        }
    }
}

The DoPaint method does exactly what the default implementation is doing, but the commented line:

 //e.Graphics.Clear(WindowBackColor);

which actually makes the background entirely black, with the WindowBackColor is set to transparent.