C#GDI+ 處理文本的兩個小技巧

 

*****本文出自:

 

http://www.cnblogs.com/08shiyan/p/3470427.html

 

1

 

代碼:

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();

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

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

            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, 20, 20, sf);

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

            f.Dispose();

            bf.Dispose();


 

 


 

效果:

 

2

 

代碼:

 

        private void button1_Click(object sender, EventArgs e)
        {
            Graphics g = this.CreateGraphics();

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

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

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

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

            f.Dispose();


 

 

 

 


 

 

效果:

 

發佈了85 篇原創文章 · 獲贊 20 · 訪問量 29萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章