Beispiel #1
0
        protected override void OnPaint(PaintEventArgs args)
        {
            base.OnPaint(args);

            Graphics graph = args.Graphics;

            // in vc, there is PrepareDC in which I can set MapMode for CDC object, we don't have to Setup CDC object in OnPaint()
            // todo: find an alternative PrepareDC in C#.
            GraphicsMapper.InitGraphics(graph);

            Point pt = GraphicsMapper.Instance.TransformPoint(AutoScrollPosition);

            graph.TranslateTransform(pt.X, pt.Y);

            PrePaint(args);

            // paint each drawingTool.
            DrawingTools.All(tool =>
            {
                tool.Paint(args);
                return(true);
            });
        }
Beispiel #2
0
        public Image GetDraggingImage(int width, int height)
        {
            Bitmap img  = null;
            Size   size = GraphicsMapper.Instance.TransformSize(new Size(width, height), CoordinateSpace.Device, CoordinateSpace.Page);

            using (Bitmap tmpImage = new Bitmap(size.Width, size.Height))
            {
                using (Graphics graph = Graphics.FromImage(tmpImage))
                {
                    GraphicsMapper.InitGraphics(graph);
                    OnPaint(new PaintEventArgs(graph, Rectangle.Empty));
                }

                size = GraphicsMapper.Instance.TransformSize(SurroundingRect.Size, CoordinateSpace.Device, CoordinateSpace.Page);
                img  = new Bitmap(size.Width + 1, size.Height + 1);
                using (Graphics graph = Graphics.FromImage(img))
                {
                    Rectangle rect = GraphicsMapper.Instance.TransformRectangle(SurroundingRect, CoordinateSpace.Device, CoordinateSpace.Page);
                    graph.DrawImage(tmpImage, 0, 0, rect, GraphicsUnit.Pixel);
                }
            }

            return(img);
        }