日期:2014-05-17 浏览次数:21348 次
private void button1_Click(object sender, EventArgs e)
{
if (this.label1.Text == "xxx")
{
this.label1.Text = "xxxx";
this.label1.Font = new Font("SimSun", 20);
}
else
{
this.label1.Text = "xxx";
this.label1.Font = new Font("SimSun", 30);
}
}
private float chang_text_size(string s, int width,int height)
{
float size=0f;
size = (float)((width * 1.2) / s.Length);//1.2是我自己测算出来的
if (size > height - 3) //3也是自己测算出来的
{
size = height - 3;
}
return size;
}
this.label1.Font = new System.Drawing.Font("宋体", chang_text_size(textBox1.Text, label1.Width, label1.Height), System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128)));测试可以实现你要求的功能