AutoSize属性为true的Label
我在窗体上定义一个Lable用来提示错误信息,错误信息是通过参数传来的,由于Lable初始化时宽度是固定的所以我把它的AutoSize属性设置为True,当宽度不够时自动加长。可是后面在设置Label的Location属性时我需要得到Label的Width,但得到的仍然是默认初始化时的宽度,比如我传进的字符数为50个,Label的宽度取的仍然是默认值100。。
怎么才能取得Label的实际宽度呢?
我的代码
Lable lbl = new Lable();lbl.Text = errmsg; lbl.Font = new System.Drawing.Font("宋体", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); lbl.Location = new Point((panelControl2.Width-lbl.Width)/2, picturebox.Location.Y + picturebox.Height + 30);