Exemplo n.º 1
0
 private void InitDrawTools()
 {
     // 그리기 도구
     DrawRect.X             = X;
     DrawRect.Y             = Y;
     DrawRect.Width         = Width;
     DrawRect.Height        = Height;
     rRect                  = DrawHelper.CreateRoundedRectanglePath(DrawRect, 4);
     tempRect               = new Rectangle(DrawRect.X + 1, DrawRect.Y + 1, DrawRect.Width - 2, DrawRect.Height - 2);
     pLine.DashStyle        = System.Drawing.Drawing2D.DashStyle.Dot;
     pLine.DashCap          = System.Drawing.Drawing2D.DashCap.Round;
     pButtonGuide.DashStyle = DashStyle.Dash;
     format.Alignment       = TextAlign;
     format.LineAlignment   = StringAlignment.Center;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 오브젝트를 컨트롤에 그립니다.
        /// </summary>
        /// <param name="g">그래픽 객체</param>
        /// <param name="flag">개발자모드 플래그값(True:편집모드, False:런타임모드)</param>
        public void Drawing(Graphics g, bool flag)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            System.Drawing.Drawing2D.Matrix mat = new System.Drawing.Drawing2D.Matrix();
            mat.RotateAt(RotationAngle, new PointF(X + (Width / 2), Y + (Height / 2)));
            //if (!flag)
            g.Transform = mat;

            InitDrawTools();

            if (!Visible && !flag)
            {
                return;
            }

            // 타입에 따른 그리기
            switch (_type)
            {
            // **************************************************************************
            // 1. pRectangle 사각형
            // **************************************************************************
            case DrawObjectType.pRectangle:
                if (_FillColor.ToArgb() != 0)
                {
                    g.FillRectangle(new SolidBrush(_FillColor), DrawRect);
                }
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawRectangle(new Pen(new SolidBrush(_LineColor), LineWidth), DrawRect);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawRectangle(pLine, DrawRect);
                    }
                }
                g.DrawString(Text.Replace("\\n", "\n"), FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;

            // **************************************************************************
            // 2. pEllipse 원형
            // **************************************************************************
            case DrawObjectType.pEllipse:
                if (_FillColor.ToArgb() != 0)
                {
                    g.FillEllipse(new SolidBrush(_FillColor), DrawRect);
                }
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawEllipse(new Pen(new SolidBrush(_LineColor), LineWidth), DrawRect);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawEllipse(pLine, DrawRect);
                    }
                }
                g.DrawString(Text.Replace("\\n", "\n"), FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;

            // **************************************************************************
            // 3. pArc 호
            // **************************************************************************
            case DrawObjectType.pArc:
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawArc(new Pen(_LineColor, LineWidth), DrawRect, Angle1, Angle2);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawArc(pLine, DrawRect, Angle1, Angle2);
                    }
                }
                break;

            // **************************************************************************
            // 4. pLine 라인
            // **************************************************************************
            case DrawObjectType.pLine:
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawLine(new Pen(_LineColor, LineWidth), new Point(X, Y), new Point(X + Width, Y));
                }
                else
                {
                    if (flag)
                    {
                        g.DrawLine(pLine, new Point(X, Y), new Point(X + Width, Y));
                    }
                }
                break;

            // **************************************************************************
            // 5. pLineNE 대각선 Line(↘)
            // **************************************************************************
            case DrawObjectType.pLineNE:
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawLine(new Pen(_LineColor, LineWidth), new Point(X, Y), new Point(X + Width, Y + Height));
                }
                else
                {
                    if (flag)
                    {
                        g.DrawLine(pLine, new Point(X, Y), new Point(X + Width, Y + Height));
                    }
                }
                break;

            // **************************************************************************
            // 6. pLineNW 대각선 Line(↙)
            // **************************************************************************
            case DrawObjectType.pLineNW:
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawLine(new Pen(_LineColor, LineWidth), new Point(X + Width, Y), new Point(X, Y + Height));
                }
                else
                {
                    if (flag)
                    {
                        g.DrawLine(pLine, new Point(X + Width, Y), new Point(X, Y + Height));
                    }
                }
                break;

            // **************************************************************************
            // 7. pImage 이미지
            // **************************************************************************
            case DrawObjectType.pImage:
                g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                if (Img != null)
                {
                    g.DrawImage(Img, DrawRect);
                }
                g.PixelOffsetMode = PixelOffsetMode.Default;
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawRectangle(new Pen(new SolidBrush(_LineColor), LineWidth), DrawRect);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawRectangle(pLine, DrawRect);
                    }
                }
                g.DrawString(Text.Replace("\\n", "\n"), FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;

            // **************************************************************************
            // 8. pButton 버튼
            // **************************************************************************
            case DrawObjectType.pButton:
                pButtonInnerLine = new Pen(new LinearGradientBrush(DrawRect, Color.FromArgb(50, _LineColor), Color.FromArgb(150, _LineColor), LinearGradientMode.ForwardDiagonal), 2.0f);
                if (_FillColor.ToArgb() != 0)
                {
                    g.FillPath(new SolidBrush(_FillColor), rRect);     // 라운드 사각형 그리기
                    if (_LineColor != Color.Blue)
                    {
                        // 버튼다운 상태가 아니라면 그라데이션을 넣어서 입체적인 느낌을 낸다.
                        g.FillRectangle(new LinearGradientBrush(tempRect, Color.FromArgb(140, Color.White), Color.FromArgb(20, Color.White), 90), tempRect.X, tempRect.Y, tempRect.Width, tempRect.Height / 2);
                    }
                    else
                    {
                        // 버튼다운 상태면 안쪽에 음영사각형을 넣어서 버튼이 들어간 느낌을 낸다.
                        g.DrawRectangle(new Pen(new SolidBrush(Color.FromArgb(60, Color.Black)), 3), tempRect.X + 2, tempRect.Y + 2, tempRect.Width - 4, tempRect.Height - 4);
                    }
                }
                if (_Visible)
                {
                    // 버튼 테두리는 검정에 두께1 고정
                    g.DrawPath(pButtonOutLine, rRect);
                    // 버튼 안 테두리는 라인색에 두께2
                    g.DrawPath(pButtonInnerLine, DrawHelper.CreateRoundedRectanglePath(tempRect, 4));
                    // 선택된 버튼은 점선 사각형으로 포커스를 활성화 한다.
                    if (bFocus)
                    {
                        //g.DrawRectangle(pButtonGuide, tempRect.X + 1, tempRect.Y + 1, tempRect.Width - 2, tempRect.Height - 2);
                        g.DrawRectangle(pLine, tempRect.X + 1, tempRect.Y + 1, tempRect.Width - 2, tempRect.Height - 2);
                    }
                }
                else
                {
                    if (flag)
                    {
                        g.DrawRectangle(pLine, DrawRect);
                    }
                }
                // 텍스트 그리기
                g.DrawString(Text.Replace("\\n", "\n"), FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;

            // **************************************************************************
            // 9. pDiamond 마름모
            // **************************************************************************
            case DrawObjectType.pDiamond:
                GraphicsPath dRect = DrawHelper.CreateDiamondPath(DrawRect);
                if (_FillColor.ToArgb() != 0)
                {
                    g.FillPath(new SolidBrush(_FillColor), dRect);
                }
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawPath(new Pen(new SolidBrush(_LineColor), LineWidth), dRect);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawRectangle(pLine, DrawRect);
                    }
                }
                g.DrawString(Text, FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;

            // **************************************************************************
            // 10. pLine 라인 (세로선)
            // **************************************************************************
            case DrawObjectType.pLineV:
                if (_LineColor.ToArgb() != 0)
                {
                    g.DrawLine(new Pen(_LineColor, LineWidth), new Point(X, Y), new Point(X, Y + Height));
                }
                else
                {
                    if (flag)
                    {
                        g.DrawLine(pLine, new Point(X, Y), new Point(X, Y + Height));
                    }
                }
                break;

            // **************************************************************************
            // 11. pRoundRect 라운드사각형
            // **************************************************************************
            case DrawObjectType.pRoundRect:

                GraphicsPath path = new GraphicsPath();
                // 상단선
                path.AddLine(new Point(DrawRect.X + (DrawRect.Height / 2), DrawRect.Y), new Point(DrawRect.X + DrawRect.Width - (DrawRect.Height / 2), DrawRect.Y));
                // 우측 Arc
                path.AddArc(new Rectangle(DrawRect.X + DrawRect.Width - (DrawRect.Height), DrawRect.Y, DrawRect.Height, DrawRect.Height), -90, 180);
                // 하단선
                path.AddLine(new Point(DrawRect.X + (DrawRect.Height / 2), DrawRect.Y + DrawRect.Height), new Point(DrawRect.X + DrawRect.Width - (DrawRect.Height / 2), DrawRect.Y + DrawRect.Height));
                // 좌측 Arc
                path.AddArc(new Rectangle(DrawRect.X, DrawRect.Y, DrawRect.Height, DrawRect.Height), 90, 180);


                if (_FillColor.ToArgb() != 0)
                {
                    //g.FillRectangle(new SolidBrush(_FillColor), DrawRect);
                    g.FillPath(new SolidBrush(_FillColor), path);
                }
                if (_LineColor.ToArgb() != 0)
                {
                    //g.DrawPath(new Pen(new SolidBrush(_LineColor), LineWidth), DrawHelper.CreateRoundedRectanglePath(DrawRect, 45));
                    g.DrawPath(new Pen(new SolidBrush(_LineColor), LineWidth), path);
                }
                else
                {
                    if (flag)
                    {
                        g.DrawPath(pLine, path);
                    }
                }
                g.DrawString(Text.Replace("\\n", "\n"), FontStyle, new SolidBrush(_FontColor), DrawRect, format);
                break;
            }
            g.ResetTransform();
            bChanged = false;
        }