예제 #1
0
파일: 2.cs 프로젝트: shinysol/rennypark
 public static void ColumnContentsFill(XGraphics graph, XPen pen, XFont font, int Column, double[] PositionX, double[] PositionY, string[] contents, Enums.ContentsAlignment align)
 {
     for (int i = 0; i <= contents.Length - 1; i++)
     {
         DrawTextinCellmm(graph, font, pen, contents[i], align, PositionX[Column], PositionY[i], PositionX[Column + 1], PositionY[i + 1], false);
     }
 }
예제 #2
0
파일: 2.cs 프로젝트: shinysol/rennypark
        public static void DrawTextinCellmm(XGraphics graph, XFont font, XPen pen, string str, Enums.ContentsAlignment align, double x1, double y1, double x2, double y2, bool wraptext, double margin = 1)
        {
            double wdth = graph.MeasureString(str, font).Width;
            double hght = graph.MeasureString(str, font).Height;

            if (wraptext)
            {
                int        txtCursor = 0;
                int        chrsTmp   = 0;
                List <int> chrs      = new List <int>();
                double     cellWdth  = GetPtfrommm(x2) - GetPtfrommm(x1) - 2 * GetPtfrommm(margin);
                while (txtCursor < str.Length - 1)
                {
                    while (graph.MeasureString(str.Substring(chrsTmp, txtCursor - chrsTmp + 1), font).Width < cellWdth)
                    {
                        if (txtCursor < str.Length - 1)
                        {
                            txtCursor += 1;
                        }
                        else
                        {
                            break;
                        }
                    }
                    chrsTmp = txtCursor;
                    chrs.Add(txtCursor);
                }
                chrsTmp = 0;
                int lineno = 0;
                foreach (int cur in chrs)
                {
                    graph.DrawString(str.Substring(chrsTmp, cur - chrsTmp + 1), font, XBrushes.Black,
                                     new XRect(GetPtfrommm(x1) + GetPtfrommm(margin), (GetPtfrommm(y1) + GetPtfrommm(margin) - GetPtfrommm(0.7) + hght * lineno), x2 - x1 - 2 *
                                               GetPtfrommm(margin), hght), XStringFormats.TopLeft);
                    chrsTmp = cur + 1;
                    lineno += 1;
                }
            }
            else
            {
                switch (align)
                {
                case Enums.ContentsAlignment.Left:

                    graph.DrawString(str, font, XBrushes.Black,
                                     new XRect(GetPtfrommm(x1) + GetPtfrommm(margin), (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft);
                    break;

                case Enums.ContentsAlignment.Right:
                    graph.DrawString(str, font, XBrushes.Black,
                                     new XRect(GetPtfrommm(x2) - GetPtfrommm(margin) - wdth, (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft);
                    break;

                case Enums.ContentsAlignment.Center:
                    graph.DrawString(str, font, XBrushes.Black,
                                     new XRect((GetPtfrommm(x1) / 2) + (GetPtfrommm(x2) / 2) - (wdth / 2), (GetPtfrommm(y1) / 2) + (GetPtfrommm(y2) / 2) - (hght / 2), wdth, hght), XStringFormats.TopLeft);
                    break;
                }
            }
        }