C# GDI+ 处理文本的两个小技巧

时间:2022-03-23 06:12:29
 private void button7_Click(object sender, EventArgs e)

        {

            Graphics g = this.CreateGraphics();

            g.FillRectangle(Brushes.White, this.ClientRectangle);

            Font f = new Font("Times New Roman", );

            Font bf = new Font(f, FontStyle.Bold);

            StringFormat sf = new StringFormat();

            float[] ts = { 10.0f, 70.0f, 100.0f, 90.0f };

            sf.SetTabStops(0.0f, ts);

            string s1 = "\tName\tHair Color\tEys Color\tHeight";

            string s2 = "\tBob\tBrown\tBrown\t175cm";

            g.DrawString(s1, bf, Brushes.Black, , , sf);

            g.DrawString(s2, f, Brushes.Blue, ,  + bf.Height, sf);

            f.Dispose();

            bf.Dispose();

        }

表格效果: C# GDI+ 处理文本的两个小技巧

        private void button8_Click(object sender, EventArgs e)

        {

            Graphics g = this.CreateGraphics();

            g.FillRectangle(Brushes.White, this.ClientRectangle);

            Font f = new Font("Times New Roman", , FontStyle.Bold);

            HatchBrush hb = new HatchBrush(HatchStyle.Cross, Color.White, Color.Black);

            g.DrawString("Ctazy Crosshatch", f, hb, , );

            f.Dispose();

        }

网格效果:C# GDI+ 处理文本的两个小技巧