用Draw的方式怎么控制字的大小和形状,让它自动充满一个我给定的矩形。

解决方案 »

  1.   

    private void button1_Click(object sender, EventArgs e)
            {
                Graphics g = this.CreateGraphics();
                SizeF MyFontSize = SizeF.Empty;
                Rectangle MyRect = new Rectangle(0, 0, 200, 100);
                Font  MyFont = new Font("Arial", 100);            string str = "这里要写qweqwewqewqeqwe什么东西";
                MyFontSize = g.MeasureString("String to draw ...", MyFont);
                while (MyFontSize.Width > MyRect.Width ||            MyFontSize.Height > MyRect.Height)
                {                MyFont = new Font("Arial", (MyFont.Size - .01F));
                    MyFontSize = g.MeasureString(str, MyFont);
                }
               
                g.DrawRectangle(Pens.Black,0,0,MyFontSize.Width,MyFontSize.Height);
                
                g.DrawString(str, MyFont, Brushes.Black, new PointF(0, 0));        }
    完整充满一个矩形。
      

  2.   

    delicioustian(天天酷鱼) 你的方法只是同单位长度的缩小如果想要填满一个100*200的随意的矩形该怎么做?