示例#1
0
        public static String[,] AlignString(String[,] Data, String[] Filler,int[] columnSpace , Font Font)
        {
            int NRow = Data.GetLength(0);
            int NCol = Data.GetLength(1);
            String[,] result = new String[NRow, NCol];

            System.Windows.Forms.Button aButton = new System.Windows.Forms.Button();
            Graphics G = aButton.CreateGraphics();
            System.Drawing.StringFormat sf = System.Drawing.StringFormat.GenericTypographic;
            sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

            for (int j = 0; j < NCol; j++)
            {
                //計算此欄字串的最大長度
                SizeF maxSize = G.MeasureString(Data[0, j], Font, 0, sf);
                for (int i = 1; i < NRow; i++)
                {
                    SizeF sizeF = G.MeasureString(Data[i, j], Font, 0, sf);
                    if (sizeF.Width > maxSize.Width)
                        maxSize = sizeF;
                }

                SizeF fillerSizeF = G.MeasureString(Filler[j], Font, 0, sf);
                SizeF ColSize = new SizeF(maxSize.Width + fillerSizeF.Width * columnSpace[j], maxSize.Height);

                for (int i = 0; i < NRow; i++)
                {
                    result[i, j] = Data[i, j];
                    while (G.MeasureString(result[i, j], Font, 0, sf).Width < ColSize.Width)
                        result[i, j] += Filler[j];
                }
            }

            return result;
        }
        public static void ToTransparent(this System.Windows.Forms.Button Button, System.Drawing.Color TransparentColor)
        {
            Bitmap bmp = ((Bitmap)Button.Image);

            //Bitmap bmp = new Bitmap(100, 100);
            //Button.Image = bmp;
            bmp.MakeTransparent(TransparentColor);
            int      x  = (Button.Width - bmp.Width) / 2;
            int      y  = (Button.Height - bmp.Height) / 2;
            Graphics gr = Button.CreateGraphics();

            gr.DrawImage(bmp, x, y);
        }
示例#3
0
        public static String[,] AlignString(String[,] Data, String[] Filler, int[] columnSpace, Font Font)
        {
            int NRow = Data.GetLength(0);
            int NCol = Data.GetLength(1);

            String[,] result = new String[NRow, NCol];

            System.Windows.Forms.Button aButton = new System.Windows.Forms.Button();
            Graphics G = aButton.CreateGraphics();

            System.Drawing.StringFormat sf = System.Drawing.StringFormat.GenericTypographic;
            sf.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;

            for (int j = 0; j < NCol; j++)
            {
                //計算此欄字串的最大長度
                SizeF maxSize = G.MeasureString(Data[0, j], Font, 0, sf);
                for (int i = 1; i < NRow; i++)
                {
                    SizeF sizeF = G.MeasureString(Data[i, j], Font, 0, sf);
                    if (sizeF.Width > maxSize.Width)
                    {
                        maxSize = sizeF;
                    }
                }

                SizeF fillerSizeF = G.MeasureString(Filler[j], Font, 0, sf);
                SizeF ColSize     = new SizeF(maxSize.Width + fillerSizeF.Width * columnSpace[j], maxSize.Height);

                for (int i = 0; i < NRow; i++)
                {
                    result[i, j] = Data[i, j];
                    while (G.MeasureString(result[i, j], Font, 0, sf).Width < ColSize.Width)
                    {
                        result[i, j] += Filler[j];
                    }
                }
            }

            return(result);
        }