Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            if (BackColor == Color.Transparent || BackColor.A < 255)
            {
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                int hScrollHeight = (this.HScroll ? SystemInformation.HorizontalScrollBarHeight : 0);
                int vScrollWidth  = (this.VScroll ? SystemInformation.VerticalScrollBarWidth : 0);

                int borderWidth = ((this.Width - this.ClientSize.Width) - vScrollWidth) / 2;

                System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                e.Graphics.TranslateTransform(-(Left + borderWidth), -(Top + borderWidth));
                PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                e.Graphics.ResetTransform();
                e.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
            }

            ControlRenderer.PaintMgPanel(this, e.Graphics);
        }
        void Draw(System.Drawing.Graphics g, System.Drawing.Drawing2D.AdjustableArrowCap customStartCap, System.Drawing.Drawing2D.AdjustableArrowCap customEndCap)
        {
            System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer();
            System.Drawing.Drawing2D.Matrix            myMatrix   = g.Transform;

            float X = (float)this.X;
            float Y = (float)this.Y;

            if (m_Rotation != 0)
            {
                myMatrix.RotateAt((float)m_Rotation, new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append);
                g.Transform = myMatrix;
            }
            System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth);

            // put startcaps and endcaps on lines
            if (customStartCap != null)
            {
                myPen.CustomStartCap = customStartCap;
            }
            if (customEndCap != null)
            {
                myPen.CustomEndCap = customEndCap;
            }

            g.DrawLine(myPen, X, Y, X + m_Size.Width, Y + m_Size.Height);
            g.EndContainer(gContainer);
        }
Exemple #3
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Simulate Transparency
            System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
            Rectangle translateRect = this.Bounds;

            pevent.Graphics.TranslateTransform(-this.Left, -this.Top);
            PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);

            this.InvokePaintBackground(this.Parent, pe);
            this.InvokePaint(this.Parent, pe);
            pevent.Graphics.ResetTransform();
            pevent.Graphics.EndContainer(g);
            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Color fillColor = SkinInfo.BackColor;

            Rectangle r = this.ClientRectangle;


            Color col = GetParentBackColor(this);

            if (currentState == CustomButtonState.Hot)
            {
                col = col.ModifyLuminosity(-0.01);
            }

            using (Brush bgBrush = new SolidBrush(col))
            {
                pevent.Graphics.FillRectangle(bgBrush, r);
            }

            contentRect = r;
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pevent"></param>
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Simulate Transparency
            if (BackColor == Color.Transparent || BackColor.A < 255)
            {
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                pevent.Graphics.TranslateTransform(-Left, -Top);
                PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                pevent.Graphics.ResetTransform();
                pevent.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
            }

            DrawBackground(pevent.Graphics, ClientRectangle);
        }
Exemple #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pevent"></param>
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Simulate Transparency
            if (BackColor == Color.Transparent || BackColor.A < 255)
            {
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                pevent.Graphics.TranslateTransform(-Left, -Top);
                PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                pevent.Graphics.ResetTransform();
                pevent.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
            }

            ControlRenderer.FillRectAccordingToGradientStyle(pevent.Graphics, this.ClientRectangle, BackColor, ForeColor,
                                                             ControlStyle.NoBorder, false, GradientColor, GradientStyle);

            if (TransparentChild != null && DesignMode)
            {
                ControlRenderer.RenderOwnerDrawnControlsOfParent(pevent.Graphics, TransparentChild);
            }
        }
        protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                      Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            // Paint the base content
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                       value, formattedValue, errorText, cellStyle,
                       advancedBorderStyle, paintParts);

            if (this.Image != null)
            {
                // Draw the image clipped to the cell.
                System.Drawing.Drawing2D.GraphicsContainer container =
                    graphics.BeginContainer();

                graphics.SetClip(cellBounds);
                Rectangle rect = new Rectangle();
                rect.Location = new Point(cellBounds.Location.X + cellBounds.Width - this.Image.Width - 1, cellBounds.Location.Y + 1);
                rect.Size     = new Size(this.Image.Width, cellBounds.Height - 2);

                //Draw image scaled, the image will be resized to fit the cell
                graphics.DrawImage(this.Image, rect);

                //Draw image unscaled, the image size will keep unchanged.
                //graphics.DrawImageUnscaled(this.Image, rect);

                graphics.EndContainer(container);
            }
        }
Exemple #7
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                      Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            // Paint the base content
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                       value, formattedValue, errorText, cellStyle,
                       advancedBorderStyle, paintParts);

            if (this.Image != null)
            {
                // Draw the image clipped to the cell.
                System.Drawing.Drawing2D.GraphicsContainer container =
                    graphics.BeginContainer();

                graphics.SetClip(cellBounds);

                Point imageLocation = cellBounds.Location;
                imageLocation.X += 10;
                graphics.DrawImageUnscaled(this.Image, imageLocation);

                graphics.EndContainer(container);
            }
        }
Exemple #8
0
        public override void Draw(System.Drawing.Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer();
            System.Drawing.Drawing2D.Matrix            myMatrix   = g.Transform;
            this.DetermineOffset();
            float X = (float)this.m_parentAtom.X;
            float Y = (float)this.m_parentAtom.Y;

            if (m_Rotation != 0)
            {
                myMatrix.RotateAt((float)(m_Rotation), new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append);
                g.Transform = myMatrix;
            }
            System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth);
            if (this.m_BondType == ChemInfo.BondType.Single || this.m_BondType == ChemInfo.BondType.Aromatic)
            {
                g.DrawLine(myPen, X, Y, m_connectedAtom.X, m_connectedAtom.Y);
            }
            if (this.m_BondType == ChemInfo.BondType.Double)
            {
                g.DrawLine(myPen, X + m_OffsetX, Y + m_OffsetY, m_connectedAtom.X + m_OffsetX, m_connectedAtom.Y + m_OffsetY);
                g.DrawLine(myPen, X - m_OffsetX, Y - m_OffsetY, m_connectedAtom.X - m_OffsetX, m_connectedAtom.Y - m_OffsetY);
            }
            if (this.m_BondType == ChemInfo.BondType.Triple)
            {
                g.DrawLine(myPen, X + m_OffsetX, Y + m_OffsetY, m_connectedAtom.X + m_OffsetX, m_connectedAtom.Y + m_OffsetY);
                g.DrawLine(myPen, X, Y, m_connectedAtom.X, m_connectedAtom.Y);
                g.DrawLine(myPen, X - m_OffsetX, Y - m_OffsetY, m_connectedAtom.X - m_OffsetX, m_connectedAtom.Y - m_OffsetY);
            }
            g.EndContainer(gContainer);
        }
Exemple #9
0
 private void RealPaintingCanvas_Paint(object sender, PaintEventArgs e)
 {
     System.Drawing.Drawing2D.GraphicsContainer containerState = e.Graphics.BeginContainer();
     e.Graphics.ScaleTransform(1.0F, -1.0F);
     e.Graphics.TranslateTransform(0.0F, -(float)this.realPaintingCanvas.Height + 1.0f);
     if (actualDrawingStructure != null)
     {
         foreach (DXFentryForDisplay item in actualDrawingStructure)
         {
             if (item is MyDxfLineForDisplay)
             {
                 MyDxfLineForDisplay item2 = item as MyDxfLineForDisplay;
                 e.Graphics.DrawLine(item2.penStructure,
                                     (float)(item2.XStart * internalScaleFactor + 1),
                                     (float)(item2.YStart * internalScaleFactor + 1),
                                     (float)(item2.XEnd * internalScaleFactor + 1),
                                     (float)(item2.YEnd * internalScaleFactor + 1));
             }
             else if (item is MyDxfArcForDisplay)
             {
                 MyDxfArcForDisplay item2 = item as MyDxfArcForDisplay;
                 e.Graphics.DrawArc(item2.penStructure,
                                    (float)(item2.XUpper * internalScaleFactor + 1),
                                    (float)(item2.YUpper * internalScaleFactor + 1),
                                    (float)(item2.Width * internalScaleFactor), (float)(item2.Height * internalScaleFactor),
                                    (float)item2.startAngle, (float)item2.sweepAngle);
             }
         }
     }
     e.Graphics.EndContainer(containerState);
 }
Exemple #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //Simulate Transparency
            if (BackColor == Color.Transparent)
            {
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                int       borderWidth   = (this.Width - this.ClientSize.Width) / 2;
                e.Graphics.TranslateTransform(-(Left + borderWidth), -(Top + borderWidth));
                PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                e.Graphics.ResetTransform();
                e.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
            }
            else
            {
                base.OnPaintBackground(e);
            }
        }
        public override void Draw(System.Drawing.Graphics g)
        {
            System.Drawing.StringFormat format = new System.Drawing.StringFormat();
            format.Alignment     = this.m_HorizontalAlignment;
            format.LineAlignment = this.m_VerticalAlignment;
            System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer();
            System.Drawing.Drawing2D.Matrix            myMatrix   = g.Transform;
            float X = (float)this.X;
            float Y = (float)this.Y;

            if (m_Rotation != 0)
            {
                myMatrix.RotateAt((float)(m_Rotation), new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append);
                g.Transform = myMatrix;
            }
            if (m_AutoSize)
            {
                System.Drawing.SizeF mySize = g.MeasureString(m_Text, m_Font);
                m_Size.Width  = (int)mySize.Width;
                m_Size.Height = (int)mySize.Height;
                g.DrawString(m_Text, m_Font, new System.Drawing.SolidBrush(m_Color), X, Y, format);
            }
            else
            {
                System.Drawing.RectangleF rect = new System.Drawing.RectangleF(X, Y, (float)m_Size.Width, (float)m_Size.Height);
                g.DrawString(m_Text, m_Font, new System.Drawing.SolidBrush(m_Color), rect, format);
            }
            g.EndContainer(gContainer);
        }
Exemple #12
0
        protected override void OnPaint(PaintEventArgs e)
        {
            //Simulate Transparency
            if (BackColor == Color.Transparent)
            {
#if !PocketPC
                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                }

                System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                Rectangle translateRect = this.Bounds;
                e.Graphics.TranslateTransform(-Left, -Top);
                PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                this.InvokePaintBackground(Parent, pe);
                this.InvokePaint(Parent, pe);
                //fixed bug#:796041, the forgound not need to display
                //this.InvokePaint(Parent, pe);
                e.Graphics.ResetTransform();
                e.Graphics.EndContainer(g);
                pe.Dispose();

                if (Parent is ISupportsTransparentChildRendering)
                {
                    ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                }
#endif
            }

            ControlRenderer.FillRectAccordingToGradientStyle(e.Graphics, ClientRectangle, BackColor, LinkColor, 0,
                                                             false, GradientColor, GradientStyle);

            ContentAlignment newTextAlign = ControlUtils.GetOrgContentAligment(RightToLeft, TextAlign);

            FontDescription font = new FontDescription(Font);
            ControlRenderer.PrintText(e.Graphics, ClientRectangle, LinkColor, font, Text, false, newTextAlign,
                                      Enabled, true, !UseMnemonic, false, (RightToLeft == RightToLeft.Yes));

            //fixed bug #:765815 : when parking on hypertext button,focus need to seen on text on the button (not on  entire button)
            if (Focused)
            {
                Size textExt = Utils.GetTextExt(Font, Text, this);
                // get the display the focus on the text of the control
                Rectangle textRect = ControlUtils.GetFocusRect(this, ClientRectangle, newTextAlign, textExt);
                //ass offset, it will look as in online
                textRect.Inflate(2, 2);
                textRect.Width  -= 2;
                textRect.Height -= 1;

                textRect.X      = Math.Max(1, textRect.X);
                textRect.Y      = Math.Max(1, textRect.Y);
                textRect.Width  = Math.Min(textRect.Width, ClientRectangle.Width - textRect.X);
                textRect.Height = Math.Min(textRect.Height, ClientRectangle.Height - textRect.Y);

                ControlPaint.DrawFocusRectangle(e.Graphics, textRect);
            }
        }
Exemple #13
0
        protected override void OnPaint(PaintEventArgs e)
        {
            System.Drawing.Drawing2D.GraphicsContainer a = e.Graphics.BeginContainer();
            e.Graphics.TranslateTransform(m_origin.X, m_origin.Y);
            m_camera.Project(m_theta, m_phi, m_tx, m_ty, m_tz);

            DrawData(e);
            e.Graphics.EndContainer(a);
            base.OnPaint(e);
        }
Exemple #14
0
 public void DrawObjects(System.Drawing.Graphics g, double Scale)
 {
     System.Drawing.Drawing2D.GraphicsContainer gCon = g.BeginContainer();
     System.Drawing.Drawing2D.Matrix myOriginalMatrix = g.Transform;
     g.PageUnit = System.Drawing.GraphicsUnit.Pixel;
     g.ScaleTransform((float)Scale, (float)Scale);
     foreach (GraphicObject obj in this)
     {
         obj.Draw(g);
     }
     g.EndContainer(gCon);
     g.Transform = myOriginalMatrix;
 }
        private void RealPaintingPanel_Paint(object sender, PaintEventArgs e)
        {
            //https://stackoverflow.com/questions/1485745/flip-coordinates-when-drawing-to-control
            // Call the OnPaint method of the base class.
            base.OnPaint(e);
            // Begin graphics container
            System.Drawing.Drawing2D.GraphicsContainer containerState = e.Graphics.BeginContainer();
            double offset2X = 0.0; double offset2Y = 0.0;

            // Flip the Y-Axis
            e.Graphics.ScaleTransform(1.0F, -1.0F);
            e.Graphics.TranslateTransform(0.0F, -(float)Height + 1.0f);

            e.Graphics.Clear(Color.White);
            //let's have all entries shown on field, no matter how far or close are they located
            double deltaDrawingOffsetX = (0 - structToRender.GetBoundingBox().XLowerLeft) * internalScaleFactor;
            double deltaDrawingOffsetY = (0 - structToRender.GetBoundingBox().YLowerLeft) * internalScaleFactor;
            // do not cling pixel-to-pixel to lower bottom
            double deltaTinyOffsetW = Math.Abs(1 - prescaleKoefficient) / 2.0 * this.Width;
            double deltaTinyOffsetH = Math.Abs(1 - prescaleKoefficient) / 2.0 * this.Height;

            //render all
            using (System.Drawing.Pen myPen = new System.Drawing.Pen(Color.Black))
            {
                int totalNumber = structToRender.getSize();
                for (int i = 0; i < totalNumber; i++)
                {
                    DXFdrawingEntry tmpEntryFromList = structToRender.getItemByIndex(i);
                    if (tmpEntryFromList is MyDxfLine)
                    {
                        e.Graphics.DrawLine(myPen,
                                            (float)((tmpEntryFromList as MyDxfLine).XStart * internalScaleFactor + deltaDrawingOffsetX + deltaTinyOffsetW),
                                            (float)((tmpEntryFromList as MyDxfLine).YStart * internalScaleFactor + deltaDrawingOffsetY + deltaTinyOffsetH),
                                            (float)((tmpEntryFromList as MyDxfLine).XEnd * internalScaleFactor + deltaDrawingOffsetX + deltaTinyOffsetW),
                                            (float)((tmpEntryFromList as MyDxfLine).YEnd * internalScaleFactor + deltaDrawingOffsetY + deltaTinyOffsetH));
                    }
                    else if (tmpEntryFromList is MyDxfArc)
                    {
                        //width and height (3 and 4 parametrs) should be scaled and not translated
                        e.Graphics.DrawArc(myPen,
                                           (float)((tmpEntryFromList as MyDxfArc).drawUpperLeftX * internalScaleFactor + deltaDrawingOffsetX + deltaTinyOffsetW),
                                           (float)((tmpEntryFromList as MyDxfArc).drawUpperLeftY * internalScaleFactor + deltaDrawingOffsetY + deltaTinyOffsetH),
                                           (float)((tmpEntryFromList as MyDxfArc).drawDimensionHorizontal * internalScaleFactor),
                                           (float)((tmpEntryFromList as MyDxfArc).drawDimensionVertical * internalScaleFactor),
                                           (float)((tmpEntryFromList as MyDxfArc).drawStartAngleDegreeCW),
                                           (float)((tmpEntryFromList as MyDxfArc).drawSweepAngleDegree));
                    }
                }
            }
            e.Graphics.EndContainer(containerState);
        }
Exemple #16
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Draw the Parent onto our Control to give pseudo transparency.
            //The BeginContainer and EndContainer calls stop incorrect painting of
            //child controls when both container and child have BackColor set to Transparent.
            //This only happens as a result of the TranslateTransform() call.
            System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
            Rectangle translateRect = this.Bounds;

            pevent.Graphics.TranslateTransform(-this.Left, -this.Top);
            PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);

            this.InvokePaintBackground(this.Parent, pe);
            this.InvokePaint(this.Parent, pe);
            pevent.Graphics.ResetTransform();
            pevent.Graphics.EndContainer(g);

            //Define the custom Border Region, Brush and Pen.
            System.Drawing.Drawing2D.GraphicsPath border;
            Brush     paintBrush = new SolidBrush(this.BackColor);
            Pen       borderPen  = new Pen(this.ForeColor);
            Rectangle r          = this.ClientRectangle;

            //Set the Region of the Control
            this.Region = new Region(RoundRegion(r));

            r.Inflate(-1, -1);
            border = RoundRegion(r);

            //Fill The Region with the Controls BackColor
            pevent.Graphics.FillPath(paintBrush, border);

            //Paint any BackgroundImage that might have been set
            if (this.BackgroundImage != null)
            {
                Brush br = new TextureBrush(this.BackgroundImage);
                pevent.Graphics.FillPath(br, border);
                br.Dispose();
            }

            //Draw the Region
            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            pevent.Graphics.DrawPath(borderPen, border);

            //Clean Up
            borderPen.Dispose();
            paintBrush.Dispose();
            border.Dispose();
        }
        public override void Draw(System.Drawing.Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsContainer gContainer = g.BeginContainer();
            System.Drawing.Drawing2D.Matrix            myMatrix   = g.Transform;
            float X = (float)this.X;
            float Y = (float)this.Y;

            if (m_Rotation != 0)
            {
                myMatrix.RotateAt((float)(m_Rotation), new System.Drawing.PointF(X, Y), System.Drawing.Drawing2D.MatrixOrder.Append);
                g.Transform = myMatrix;
            }
            System.Drawing.Pen myPen = new System.Drawing.Pen(m_lineColor, (float)m_lineWidth);

            g.DrawLine(myPen, X, Y, X + m_Size.Width, Y + m_Size.Height);
            g.EndContainer(gContainer);
        }
Exemple #18
0
        /// <summary>
        /// Overrides Paint
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="clipBounds"></param>
        /// <param name="cellBounds"></param>
        /// <param name="rowIndex"></param>
        /// <param name="cellState"></param>
        /// <param name="value"></param>
        /// <param name="formattedValue"></param>
        /// <param name="errorText"></param>
        /// <param name="cellStyle"></param>
        /// <param name="advancedBorderStyle"></param>
        /// <param name="paintParts"></param>
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            //TODO : improve we assume it is a 16x16 image
            if (((TextAndImage)this.Value).Image != null)
            {
                Padding inheritedPadding = this.InheritedStyle.Padding;
                this.Style.Padding = new Padding(18, inheritedPadding.Top, inheritedPadding.Right, inheritedPadding.Bottom);
                // Draw the image clipped to the cell.
                System.Drawing.Drawing2D.GraphicsContainer container = graphics.BeginContainer();
                graphics.SetClip(cellBounds);
                graphics.DrawImageUnscaled(((TextAndImage)this.Value).Image, new Point(cellBounds.Location.X + 2, cellBounds.Location.Y + ((cellBounds.Height - 16) / 2) - 1));
                graphics.EndContainer(container);
            }

            // Paint the base content
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
        }
Exemple #19
0
        /// <summary> Paints the control. </summary>
        private void PaintNotFocusedControl()
        {
            Debug.Assert(!Focused);

            using (Graphics gr = Graphics.FromHwnd(this.Handle))
            {
                //Simulate Transparency
                if (IsTransparent || BackColor.A < 255)
                {
                    if (Parent is ISupportsTransparentChildRendering)
                    {
                        ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                    }

                    System.Drawing.Drawing2D.GraphicsContainer g = gr.BeginContainer();
                    Rectangle translateRect = this.Bounds;
                    int       borderWidth   = (this.Width - this.ClientSize.Width) / 2;
                    gr.TranslateTransform(-(Left + borderWidth), -(Top + borderWidth));
                    PaintEventArgs pe = new PaintEventArgs(gr, translateRect);
                    this.InvokePaintBackground(Parent, pe);
                    this.InvokePaint(Parent, pe);
                    gr.ResetTransform();
                    gr.EndContainer(g);
                    pe.Dispose();

                    if (Parent is ISupportsTransparentChildRendering)
                    {
                        ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                    }
                }

                Rectangle rect = this.ClientRectangle;

                //In case of Fixed Single border style, we get same client rectangle & bounds. So we need to reduce them to draw the 2D border.
                if (BorderStyle == BorderStyle.FixedSingle)
                {
                    rect.Inflate(-2, -2);
                }

                ControlRenderer.PaintBackGround(gr, rect, (IsTransparent ? Color.Transparent : this.BackColor), Enabled || IsTransparent);

                PaintForeground(gr, rect, ForeColor);
            }
        }
        private void picBoard_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.PageUnit = GraphicsUnit.Pixel;

            //图片尺寸:400*300,DPI:96
            e.Graphics.DrawImageUnscaled(UserValidationOfFillingImage.Properties.Resources.hehua, DISTANCE_FROM_SIDE_X, DISTANCE_FROM_SIDE_Y);

            System.Drawing.Drawing2D.GraphicsContainer gc = e.Graphics.BeginContainer();
            try
            {
                e.Graphics.FillRectangle(Brushes.Orange, m_dragRegion);
                e.Graphics.TranslateTransform(DISTANCE_FROM_SIDE_X + m_unfilledRegionStartX, DISTANCE_FROM_SIDE_Y + UNFILLED_RERION_START_Y);
                e.Graphics.FillPath(Brushes.Red, m_unfilledRegion.ClipRegion);
            }
            finally
            {
                e.Graphics.EndContainer(gc);
            }

            e.Graphics.DrawImageUnscaled(m_cuttedImage, m_dragRegion.X, DISTANCE_FROM_SIDE_Y + UNFILLED_RERION_START_Y);
        }
Exemple #21
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                      Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState,
                       value, formattedValue, errorText, cellStyle,
                       advancedBorderStyle, paintParts);

            if (Image != null)
            {
                System.Drawing.Drawing2D.GraphicsContainer container =
                    graphics.BeginContainer();

                graphics.SetClip(cellBounds);
                graphics.DrawImageUnscaled(Image, cellBounds.Location.X, cellBounds.Location.Y + 3);

                graphics.EndContainer(container);
            }
        }
Exemple #22
0
        /// <summary></summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (IsBasePaint)
            {
                base.OnPaint(e);
            }
            else
            {
#if !PocketPC
                //Simulate Transparency
                if (BackColor == Color.Transparent || BackColor.A < 255)
                {
                    if (Parent is ISupportsTransparentChildRendering)
                    {
                        ((ISupportsTransparentChildRendering)Parent).TransparentChild = this;
                    }

                    System.Drawing.Drawing2D.GraphicsContainer g = e.Graphics.BeginContainer();
                    Rectangle translateRect = this.Bounds;
                    e.Graphics.TranslateTransform(-Left, -Top);
                    PaintEventArgs pe = new PaintEventArgs(e.Graphics, translateRect);
                    this.InvokePaintBackground(Parent, pe);
                    this.InvokePaint(Parent, pe);
                    e.Graphics.ResetTransform();
                    e.Graphics.EndContainer(g);
                    pe.Dispose();

                    if (Parent is ISupportsTransparentChildRendering)
                    {
                        ((ISupportsTransparentChildRendering)Parent).TransparentChild = null;
                    }
                }
#endif

                TextToDisplay = Text;
                ButtonRenderer.DrawButton(this, e, true, true);
            }
        }
Exemple #23
0
        public void DrawSelectedObject(System.Drawing.Graphics g, GraphicObject selectedObject, double Scale)
        {
            System.Drawing.Drawing2D.GraphicsContainer gCon1 = g.BeginContainer();
            g.ScaleTransform((float)Scale, (float)Scale, System.Drawing.Drawing2D.MatrixOrder.Append);
            System.Drawing.Drawing2D.GraphicsContainer gCon2 = g.BeginContainer();
            g.PageUnit = System.Drawing.GraphicsUnit.Pixel;

            if (selectedObject != null)
            {
                System.Drawing.Pen selectionPen = new System.Drawing.Pen(System.Drawing.Color.FromKnownColor(System.Drawing.KnownColor.HotTrack));
                selectionPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                selectionPen.Width = 1;

                if (selectedObject.Rotation != 0)
                {
                    System.Drawing.Drawing2D.Matrix myMatrix = g.Transform;
                    myMatrix.RotateAt((float)selectedObject.Rotation, new System.Drawing.PointF((float)selectedObject.X, (float)selectedObject.Y), System.Drawing.Drawing2D.MatrixOrder.Append);
                    g.Transform = myMatrix;
                }
            }
            g.EndContainer(gCon2);
            g.EndContainer(gCon1);
        }
Exemple #24
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Simulate Transparency
            System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
            Rectangle translateRect = this.Bounds;

            pevent.Graphics.TranslateTransform(-this.Left, -this.Top);
            PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);

            this.InvokePaintBackground(this.Parent, pe);
            this.InvokePaint(this.Parent, pe);
            pevent.Graphics.ResetTransform();
            pevent.Graphics.EndContainer(g);

            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            var bolder = GetEffectiveBorderColor();
            var back   = GetEffectiveBackColor();
            var rec    = new Rectangle(1, 1, Width - 3, Height - 3);

            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            //pevent.Graphics.Clear(Color.Transparent);

            using (var b = new SolidBrush(back))
                pevent.Graphics.FillEllipse(b, rec);

            if (_checked)
            {
                using (var b = new SolidBrush(_seletedColor))
                    pevent.Graphics.FillEllipse(b, new Rectangle(1 + 7, 1 + 7, Width - 3 - 7 * 2, Height - 3 - 7 * 2));
            }

            using (var p = new Pen(bolder, 2F))
                pevent.Graphics.DrawEllipse(p, rec);
        }
Exemple #25
0
 public void EndContainer(System.Drawing.Drawing2D.GraphicsContainer container)
 {
     throw new NotImplementedException();
 }
        void PaintCell(Rectangle initCellBounds, Graphics g)
        {
            System.Drawing.Drawing2D.GraphicsContainer con = g.BeginContainer();
            Rectangle cellBounds = initCellBounds;

            //Rectangle drawRect = initCellBounds;
            #region test

            /*
             * if (ColSpan > 1)
             * {
             *  cellBounds = new Rectangle(cellBounds.X, cellBounds.Y, 0, cellBounds.Height);
             *  cellBounds.Width = _parent.GetColumnSize(this.ColumnIndex, ColSpan);
             *
             * }
             * if (RowSpan > 1)
             * {
             *  int firstRow = RowIndex;
             *  int lastRow = RowIndex + RowSpan-1;
             *  int minus = 0;
             *  if (RowIndex < _parent.FirstDisplayedCell.RowIndex)
             *  {
             *      firstRow = _parent.FirstDisplayedCell.RowIndex;
             *      minus = _parent.GetRowsSize(RowIndex, firstRow - RowIndex);// RowIndex - _parent.FirstDisplayedCell.RowIndex;
             *  }
             *  if (lastRow > (_parent.FirstDisplayedCell.RowIndex + _parent.DisplayedRowCount(true)))
             *  {
             *      lastRow = (_parent.FirstDisplayedCell.RowIndex + _parent.DisplayedRowCount(true))-1;
             *  }
             *  Rectangle firstRect = _parent.GetCellDisplayRectangle(this.ColumnIndex, firstRow, true);
             *  Rectangle lastRect = _parent.GetCellDisplayRectangle(this.ColumnIndex, lastRow, true);
             *  drawRect = new Rectangle(firstRect.X, firstRect.Y, firstRect.Width, lastRect.Y - firstRect.Y + lastRect.Height);
             *
             *  cellBounds = new Rectangle(drawRect.X, drawRect.Y-minus, drawRect.Width, _parent.GetRowsSize(RowIndex, RowSpan));
             *
             * }
             *
             * if (ColSpan > 1 || RowSpan > 1)
             * {
             *  CellFunctions.DrawPlainBackground(this, _enabled, drawRect, g, this.RowIndex, false, _parent.GridColor);
             *
             *
             * }
             * else
             * {
             *  CellFunctions.DrawPlainBackground(this, _enabled, drawRect, g, this.RowIndex, this.Selected, _parent.GridColor);
             * }
             */
            #endregion

            int textY      = CellFunctions.TextCenterYInRact(cellBounds, g, _font);// cellBounds.Y + (int)((cellBounds.Height - textSize.Height) / 2.0);
            int textMargin = _textMargin;

            SizeF textSize = g.MeasureString(Text, _font);
            textSize.Width -= textMargin;

            if (textY < cellBounds.Y) //|| (textY + textSize.Height) > (cellBounds.Y + cellBounds.Height))
            {
                //don't draw text..
            }
            else
            {
                if (TextViewMode == TextViewModes.ResizeForCellWid)
                {
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

                    DrawStringResizedForCellWid(textSize, cellBounds, textMargin, textY, g);
                }
                else if (TextViewMode == TextViewModes.MultiLines)
                {
                    int newHeight = (OwningRow as EasyGridRow).SetRowHeight();
                    cellBounds.Height = newHeight;
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);

                    DrawStringMultiLines(cellBounds, textMargin, textY, g);
                }
                else //default.. single line..
                {
                    CellFunctions.DrawPlainBackground(this, _enabled, cellBounds, g, this.RowIndex, this.Selected, _parent.GridColor);
                    DrawSingleLine(cellBounds, g, textSize, textY, textMargin);
                    //DrawStringNormal(size, cellBounds, textMargin, textY, g);
                    //g.DrawString(Text, _font, _fontColor, cellBounds.X + 2, textY);
                }
                //int y = drawRect.Y + drawRect.Height - 1;
                //g.DrawLine(new Pen(_parent.GridColor, 0.1f), drawRect.X, y, drawRect.X + drawRect.Width, y);
            }

            g.EndContainer(con);
            g.Flush();
        }
 private GraphicsContainer(System.Drawing.Drawing2D.GraphicsContainer graphicsContainer)
 {
     WrappedGraphicsContainer = graphicsContainer;
 }
Exemple #28
0
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            //Simulate Transparency
            System.Drawing.Drawing2D.GraphicsContainer g = pevent.Graphics.BeginContainer();
            Rectangle translateRect = this.Bounds;

            pevent.Graphics.TranslateTransform(-this.Left, -this.Top);
            PaintEventArgs pe = new PaintEventArgs(pevent.Graphics, translateRect);

            this.InvokePaintBackground(this.Parent, pe);
            this.InvokePaint(this.Parent, pe);
            pevent.Graphics.ResetTransform();
            pevent.Graphics.EndContainer(g);

            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            Color shadeColor, fillColor;
            Color darkColor       = DarkenColor(this.BackColor, 10);
            Color darkDarkColor   = DarkenColor(this.BackColor, 25);
            Color lightColor      = LightenColor(this.BackColor, 25);
            Color lightLightColor = LightenColor(this.BackColor, 60);

            // 不显示渐变
            if (!GradientMode)
            {
                darkColor       = this.BackColor;
                darkDarkColor   = this.BackColor;
                lightColor      = this.BackColor;
                lightLightColor = this.BackColor;
            }
            else
            {
            }


            if (this.ButtonState == CustomButtonState.Hot)
            {
                fillColor  = lightColor;
                shadeColor = darkDarkColor;
            }
            else if (this.ButtonState == CustomButtonState.Pressed)
            {
                fillColor  = this.BackColor;
                shadeColor = this.BackColor;
            }
            else
            {
                fillColor  = this.BackColor;
                shadeColor = darkDarkColor;
            }

            Rectangle r = this.ClientRectangle;

            System.Drawing.Drawing2D.GraphicsPath path = RoundRectangle(r, this.CornerRadius, this.RoundCorners);

            System.Drawing.Drawing2D.LinearGradientBrush paintBrush = new System.Drawing.Drawing2D.LinearGradientBrush(r, fillColor, shadeColor, System.Drawing.Drawing2D.LinearGradientMode.Vertical);


            //We want a sharp change in the colors so define a Blend for the brush
            if (ShadeMode)
            {
                System.Drawing.Drawing2D.Blend b = new System.Drawing.Drawing2D.Blend();
                b.Positions      = new float[] { 0, 0.45F, 0.55F, 1 };
                b.Factors        = new float[] { 0, 0, 1, 1 };
                paintBrush.Blend = b;
            }

            //Draw the Button Background
            pevent.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            pevent.Graphics.FillPath(paintBrush, path);
            paintBrush.Dispose();

            //...and border
            Pen drawingPen = new Pen(BorderColor);

            pevent.Graphics.DrawPath(drawingPen, path);
            drawingPen.Dispose();

            //Get the Rectangle to be used for Content
            bool inBounds = false;

            //We could use some Math to get this from the radius but I'm
            //not great at Math so for the example this hack will suffice.
            while (!inBounds && r.Width >= 1 && r.Height >= 1)
            {
                inBounds = path.IsVisible(r.Left, r.Top) &&
                           path.IsVisible(r.Right, r.Top) &&
                           path.IsVisible(r.Left, r.Bottom) &&
                           path.IsVisible(r.Right, r.Bottom);
                r.Inflate(-1, -1);
            }

            contentRect = r;
        }
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            TreeGridNode node = this.OwningNode;

            if (node == null)
            {
                return;
            }

            Image image = node.Image;

            if (this._imageHeight == 0 && image != null)
            {
                this.UpdateStyle();
            }

            // paint the cell normally
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // TODO: Indent width needs to take image size into account
            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;

            //TODO: This painting code needs to be rehashed to be cleaner
            int level = this.Level;

            //TODO: Rehash this to take different Imagelayouts into account. This will speed up drawing
            //		for images of the same size (ImageLayout.None)
            if (image != null)
            {
                Point pp;
                if (_imageHeight > cellBounds.Height)
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, cellBounds.Y + _imageHeightOffset);
                }
                else
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, (cellBounds.Height / 2 - _imageHeight / 2) + cellBounds.Y);
                }

                // Graphics container to push/pop changes. This enables us to set clipping when painting
                // the cell's image -- keeps it from bleeding outsize of cells.
                System.Drawing.Drawing2D.GraphicsContainer gc = graphics.BeginContainer();
                {
                    graphics.SetClip(cellBounds);
                    graphics.DrawImageUnscaled(image, pp);
                }
                graphics.EndContainer(gc);
            }

            // Paint tree lines
            if (node._grid.ShowLines)
            {
                using (Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f))
                {
                    linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                    bool isLastSibling  = node.IsLastSibling;
                    bool isFirstSibling = node.IsFirstSibling;
                    if (node.Level == 1)
                    {
                        // the Root nodes display their lines differently
                        if (isFirstSibling && isLastSibling)
                        {
                            // only node, both first and last. Just draw horizontal line
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isFirstSibling)
                        {
                            // first sibling doesn't draw the line extended above. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.X + 4, cellBounds.Bottom);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }
                    }
                    else
                    {
                        if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }

                        // paint lines of previous levels to the root
                        TreeGridNode previousNode   = node.Parent;
                        int          horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        while (!previousNode.IsRoot)
                        {
                            if (previousNode.HasChildren && !previousNode.IsLastSibling)
                            {
                                // paint vertical line
                                graphics.DrawLine(linePen, horizontalStop, cellBounds.Top, horizontalStop, cellBounds.Bottom);
                            }
                            previousNode   = previousNode.Parent;
                            horizontalStop = horizontalStop - INDENT_WIDTH;
                        }
                    }
                }
            }

            if (node.HasChildren || node._grid.VirtualNodes)
            {
                // Paint node glyphs
                if (node.IsExpanded)
                {
                    node._grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                }
                else
                {
                    node._grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, 10, 10));
                }
            }
        }
Exemple #30
0
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            if (!paddingok)
            {
                PrepareDraw();
                cellStyle.Padding = Style.Padding;
            }

            DataGridViewRow xrow = this.DataGridView.Rows[rowIndex];

            if (!(xrow is TreeGridRow))
            {
                return;
            }
            TreeGridRow node = (TreeGridRow)xrow;

            if (node == null)
            {
                return;
            }

            Image image = node.Image;

            if (this._imageHeight == 0 && image != null)
            {
                this.UpdateStyle();
            }

            // paint the cell normally
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

            // TODO: Indent width needs to take image size into account
            Rectangle glyphRect = new Rectangle(cellBounds.X + this.GlyphMargin, cellBounds.Y, INDENT_WIDTH, cellBounds.Height - 1);
            int       glyphHalf = glyphRect.Width / 2;

            //TODO: This painting code needs to be rehashed to be cleaner
            int level = this.Level;

            //TODO: Rehash this to take different Imagelayouts into account. This will speed up drawing
            //		for images of the same size (ImageLayout.None)
            if (image != null)
            {
                Point pp;
                if (_imageHeight > cellBounds.Height)
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, cellBounds.Y + _imageHeightOffset);
                }
                else
                {
                    pp = new Point(glyphRect.X + this.glyphWidth, (cellBounds.Height / 2 - _imageHeight / 2) + cellBounds.Y);
                }

                // Graphics container to push/pop changes. This enables us to set clipping when painting
                // the cell's image -- keeps it from bleeding outsize of cells.
                System.Drawing.Drawing2D.GraphicsContainer gc = graphics.BeginContainer();
                {
                    graphics.SetClip(cellBounds);
                    graphics.DrawImageUnscaled(image, pp);
                }
                graphics.EndContainer(gc);
            }

            // Paint tree lines
            if (((TreeGridAdvanced)(DataGridView)).ShowLines)
            {
                using (Pen linePen = new Pen(SystemBrushes.ControlDark, 1.0f))
                {
                    linePen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                    bool isLastSibling  = node.IsLastSibling;
                    bool isFirstSibling = node.IsFirstSibling;
                    if (node.Level == 1)
                    {
                        // the Root nodes display their lines differently
                        if (isFirstSibling && isLastSibling)
                        {
                            // only node, both first and last. Just draw horizontal line
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else if (isFirstSibling)
                        {
                            // first sibling doesn't draw the line extended above. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.X + 4, cellBounds.Bottom);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }
                    }
                    else
                    {
                        if (isLastSibling)
                        {
                            // last sibling doesn't draw the line extended below. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2);
                        }
                        else
                        {
                            // normal drawing draws extended from top to bottom. Paint horizontal then vertical
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top + cellBounds.Height / 2, glyphRect.Right, cellBounds.Top + cellBounds.Height / 2);
                            graphics.DrawLine(linePen, glyphRect.X + 4, cellBounds.Top, glyphRect.X + 4, cellBounds.Bottom);
                        }

                        // paint lines of previous levels to the root
                        TreeGridRow previousNode   = node.Parent;
                        int         horizontalStop = (glyphRect.X + 4) - INDENT_WIDTH;

                        if (previousNode != null)
                        {
                            while (!previousNode.IsRoot)
                            {
                                if (previousNode.HasChildren && !previousNode.IsLastSibling)
                                {
                                    // paint vertical line
                                    graphics.DrawLine(linePen, horizontalStop, cellBounds.Top, horizontalStop, cellBounds.Bottom);
                                }
                                previousNode   = previousNode.Parent;
                                horizontalStop = horizontalStop - INDENT_WIDTH;
                                if (previousNode == null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            if (node.HasChildren)
            {
                TreeGridAdvanced _grid = (TreeGridAdvanced)DataGridView;
                // Paint node glyphs
                if (node.Node.Expanded)
                {
                    if (_grid.themesenabled)
                    {
                        try
                        {
                            if (_grid.rOpen == null)
                            {
                                _grid.rOpen        = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
                                _grid.treeboxwidth = System.Convert.ToInt32(WinFormsGraphics.DPIScale * 10);
                            }
                            _grid.rOpen.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4,
                                                                               _grid.treeboxwidth, _grid.treeboxwidth));

                            /*
                             * Pen npen = Pens.Black;
                             * int recwidth = 8;
                             * int margin = 2;
                             * int leftmargin = -recwidth / 2 - 2;
                             * int topmargin = 0;
                             * Rectangle nrect = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                             *                              topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                             *                              recwidth,
                             *                              recwidth);
                             * graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                             *                      new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));*/
                        }
                        catch
                        {
                            _grid.themesenabled = false;
                        }
                    }
                    if (!_grid.themesenabled)
                    {
                        Pen       npen       = Pens.Black;
                        int       recwidth   = 8;
                        int       margin     = 2;
                        int       leftmargin = -recwidth / 2 - 2;
                        int       topmargin  = 0;
                        Rectangle nrect      = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                                                             topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                                                             recwidth,
                                                             recwidth);
                        using (Brush nbrush = new SolidBrush(cellStyle.BackColor))
                        {
                            graphics.FillRectangle(nbrush, nrect);
                            graphics.DrawRectangle(npen, nrect);
                            graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                                              new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));
                        }
                    }
                }
                else
                {
                    if (_grid.themesenabled)
                    {
                        try
                        {
                            if (_grid.rClosed == null)
                            {
                                _grid.rClosed      = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Closed);
                                _grid.treeboxwidth = System.Convert.ToInt32(WinFormsGraphics.DPIScale * 10);
                            }
                            //    node._grid.rClosed = new VisualStyleRenderer("Explorer::TreeView",2,1);
                            _grid.rClosed.DrawBackground(graphics, new Rectangle(glyphRect.X, glyphRect.Y + (glyphRect.Height / 2) - 4, _grid.treeboxwidth, _grid.treeboxwidth));
                        }
                        catch
                        {
                            _grid.themesenabled = false;
                        }
                    }
                    if (!_grid.themesenabled)
                    {
                        Pen npen       = Pens.Black;
                        int recwidth   = 8;
                        int margin     = 2;
                        int leftmargin = -recwidth / 2 - 2;
                        int topmargin  = 0;
                        using (Brush nbrush = new SolidBrush(cellStyle.BackColor))
                        {
                            Rectangle nrect = new Rectangle(leftmargin + glyphRect.X + glyphRect.Width / 2 - recwidth / 2,
                                                            topmargin + glyphRect.Y + glyphRect.Height / 2 - recwidth / 2,
                                                            recwidth,
                                                            recwidth);
                            graphics.FillRectangle(nbrush, nrect);
                            graphics.DrawRectangle(npen, nrect);
                            graphics.DrawLine(npen, new Point(nrect.X + margin, nrect.Top + recwidth / 2),
                                              new Point(nrect.X + recwidth - margin, nrect.Top + recwidth / 2));
                            graphics.DrawLine(npen, new Point(nrect.X + recwidth / 2, nrect.Top + margin),
                                              new Point(nrect.X + recwidth / 2, nrect.Top + recwidth - margin));
                        }
                    }
                }
            }
        }