예제 #1
0
        private void DoDraw()
        {
            EventsHelper.Fire(_drawing, this, EventArgs.Empty);

            CodeClock clock = new CodeClock();

            clock.Start();

            if (this.Surface != null)
            {
                System.Drawing.Graphics graphics = this.CreateGraphics();

                this.Surface.WindowID        = this.Handle;
                this.Surface.ContextID       = graphics.GetHdc();
                this.Surface.ClientRectangle = this.ClientRectangle;
                this.Surface.ClipRectangle   = this.ClientRectangle;

                DrawArgs args = new DrawArgs(this.Surface,
                                             new WinFormsScreenProxy(Screen.FromControl(this)),
                                             DrawMode.Render)
                {
                    Dpi = Dpi
                };

                _isDrawing = true;

                try
                {
                    _tile.Draw(args);

                    _lastRenderExceptionMessage = null;
                }
                catch (Exception ex)
                {
                    Platform.Log(LogLevel.Error, ex, "An error has occured while rendering the contents of a tile.");

                    _lastRenderExceptionMessage = ex is RenderingException ? ((RenderingException)ex).UserMessage : ex.Message;

                    // we cannot simply pass the existing Graphics because we haven't released its hDC yet
                    // if we do, we'll get a "Object is currently in use elsewhere" exception
                    DrawErrorMessage(_lastRenderExceptionMessage, Surface.ContextID, ClientRectangle);
                }
                finally
                {
                    graphics.ReleaseHdc(this.Surface.ContextID);
                    graphics.Dispose();

                    _isDrawing = false;
                }
            }

            //Cause the tile to paint/refresh.
            Invalidate();
            Update();

            clock.Stop();
            string str = String.Format("TileControl.Draw: {0}, {1}\n", clock.ToString(), this.Size.ToString());

            Trace.Write(str);
        }