Prod.: Engine, ver.: 6, ID: 60000191, HowTo : HowTo override DrawBackground event of VectorDrawBaseControl

HowTo : HowTo override DrawBackground event of VectorDrawBaseControl

Article60000191
TypeHowTo
ProductEngine
Version6
Date Added6/26/2007
Submitted byTrung Pham
Keywords

Subject

HowTo override DrawBackground event of VectorDrawBaseControl

Summary

HowTo override DrawBackground event of VectorDrawBaseControl in order to draw an Image to the Background.

Solution


 The following example override the DrawBackground and vdScroll events of VectorDrawBaseControl in order to draw an image as background when rendermode is Wire2d.



Bitmap m_Bitmap;



        private void Form1_Load(object sender, EventArgs e)
        {
            vdFramedControl.BaseControl.DrawBackground += new VectorDraw.Professional.Control.DrawBackgroundEventHandler(BaseControl_DrawBackground);
            vdFramedControl.BaseControl.vdScroll += new VectorDraw.Professional.Control.ScrollEventHandler(BaseControl_vdScroll);



//create a bitmap object at runtime
            m_Bitmap = new Bitmap(vdFramedControl.BaseControl.Size.Width, vdFramedControl.BaseControl.Size.Height);
            Graphics g = Graphics.FromImage(m_Bitmap);
            g.Clear(vdFramedControl.BaseControl.ActiveDocument.Palette.Background);
            g.DrawString("VDraw", SystemFonts.DefaultFont, Brushes.Red, new PointF(vdFramedControl.BaseControl.Size.Width / 2, vdFramedControl.BaseControl.Size.Height/2));
            g.Dispose();
       }



//override the vdScroll event in order the pan and scroll draw the background properly.



        void BaseControl_vdScroll(object sender, ref double cx, ref double cy, ref bool cancel)
        {
            vdRender render = sender as vdRender;
            render.ViewCenter += new gPoint(cx, cy);
            vdFramedControl.BaseControl.ActiveDocument.Redraw(false);
        }



       void BaseControl_DrawBackground(object sender, VectorDraw.Render.vdRender render, ref bool cancel)
        {
            System.Diagnostics.Debug.WriteLine("DrawBackground");
            if (m_Bitmap == null) return;
            if (!render.IsWire2d) return;//the following code is working only when 3d render is not active
            render.UnLock();
            Graphics g = render.graphics;
            if (g == null) return;
            g.Clear(render.BkColor);
            g.DrawImage(m_Bitmap, new Point(0, 0));
            g.DrawLine(Pens.Red, new Point(0, 0), new Point(render.Width, render.Height));
            render.Lock();



            cancel = true;
        }