packages/Windows API Code Pack 1.1/source/Samples/DirectX/CS/Direct2D/D2DShapes/D2DShapesControl.cs
/// <summary>
/// for use with DcRenderTarget (though it would also work with HwndRenderTarget if GDI interop was not used)
/// </summary>
/// <param name="e"></param>
for use with DcRenderTarget (though it would also work with HwndRenderTarget if GDI interop was not used)
for use with DcRenderTarget ( though it would also work with HwndRenderTarget if GDI interop was not used )
protected override void OnPaint(PaintEventArgs e)
        {
            if (!IsInitialized || DesignMode)
            {
                e.Graphics.DrawString("D2DShapesControl", Font, foregroundBrush, (float)Width / 2, (float)Height / 2);
            }
            else
            {
                lock (renderSyncObject)
                {
                    if (renderMode == RenderModes.DCRenderTarget ||
                        renderMode == RenderModes.BitmapRenderTargetOnPaint)
                    {
                        if (dcRenderTarget == null)
                            return;
                        CalculateFPS();
                        if (renderMode == RenderModes.DCRenderTarget)
                        {
                            dcRenderTarget.BindDC(e.Graphics.GetHdc(), new Rect(Left, Top, Right, Bottom));
                            RenderScene(dcRenderTarget);
                            e.Graphics.ReleaseHdc();
                            e.Graphics.DrawString(string.Format("OnPaint({0}) direct DC draw", DateTime.Now), Font, Brushes.White, 0, 2);
                            e.Graphics.DrawString(string.Format("OnPaint({0}) direct DC draw", DateTime.Now), Font, Brushes.Black, 1, 2);
                        }
                        else if (renderMode == RenderModes.BitmapRenderTargetOnPaint)
                        {
                            dcRenderTarget.BindDC(e.Graphics.GetHdc(), new Rect(Left, Top, Right, Bottom));
                            dcRenderTarget.BeginDraw();
                            dcRenderTarget.DrawBitmap(bitmapRenderTarget.Bitmap, 1.0f,
                                                      BitmapInterpolationMode.NearestNeighbor,
                                                      new RectF(0, 0, Width, Height));
                            dcRenderTarget.EndDraw();
                            e.Graphics.ReleaseHdc();
                            e.Graphics.DrawString(string.Format("OnPaint({0}) DC DrawBitmap", DateTime.Now), Font, Brushes.White, 0, 2);
                            e.Graphics.DrawString(string.Format("OnPaint({0}) DC DrawBitmap", DateTime.Now), Font, Brushes.Black, 1, 2);
                        }
                    }
                }
            }
        }
protected override void OnPaint ( PaintEventArgs e ) { if ( ! IsInitialized || DesignMode ) { e . Graphics . DrawString ( " " , Font , foregroundBrush , ( float ) Width / 2 , ( float ) Height / 2 ) ; } else { lock ( renderSyncObject ) { if ( renderMode == RenderModes . DCRenderTarget || renderMode == RenderModes . BitmapRenderTargetOnPaint ) { if ( dcRenderTarget == null ) return ; CalculateFPS ( ) ; if ( renderMode == RenderModes . DCRenderTarget ) { dcRenderTarget . BindDC ( e . Graphics . GetHdc ( ) , new Rect ( Left , Top , Right , Bottom ) ) ; RenderScene ( dcRenderTarget ) ; e . Graphics . ReleaseHdc ( ) ; e . Graphics . DrawString ( string . Format ( " " , DateTime . Now ) , Font , Brushes . White , 0 , 2 ) ; e . Graphics . DrawString ( string . Format ( " " , DateTime . Now ) , Font , Brushes . Black , 1 , 2 ) ; } else if ( renderMode == RenderModes . BitmapRenderTargetOnPaint ) { dcRenderTarget . BindDC ( e . Graphics . GetHdc ( ) , new Rect ( Left , Top , Right , Bottom ) ) ; dcRenderTarget . BeginDraw ( ) ; dcRenderTarget . DrawBitmap ( bitmapRenderTarget . Bitmap , 1.0f , BitmapInterpolationMode . NearestNeighbor , new RectF ( 0 , 0 , Width , Height ) ) ; dcRenderTarget . EndDraw ( ) ; e . Graphics . ReleaseHdc ( ) ; e . Graphics . DrawString ( string . Format ( " " , DateTime . Now ) , Font , Brushes . White , 0 , 2 ) ; e . Graphics . DrawString ( string . Format ( " " , DateTime . Now ) , Font , Brushes . Black , 1 , 2 ) ; } } } } }
for use with DcRenderTarget (though it would also work with HwndRenderTarget if GDI interop was not used)
for use with DcRenderTarget ( though it would also work with HwndRenderTarget if GDI interop was not used )
//render scene directly to DC //draw bitmap cache of the shapes to DC
e
PaintEventArgs
None