private void Form1_Load(object sender, EventArgs e)
{
PictureBox pic = new PictureBox();
Image img = Image.FromFile(@"C:\Users\SaeWind\Desktop\123\1.png");
pic.Image = (Image)img.Clone();
img.Dispose();
pic.Location = new Point(30,50);
pic.Size = pic.Image.Size;
Label lb = new Label();
lb.Text = "为哈佛撒谎发觉个";
Graphics g = Graphics.FromHwnd(lb.Handle);
SizeF size=g.MeasureString(lb.Text, lb.Font);
g.Dispose();
lb.Location = new Point(pic.Left + pic.Width / 2 - (int)size.Width / 2, pic.Top + pic.Height / 2 - (int)size.Height / 2);
this.Controls.Add(lb);
this.Controls.Add(pic);
}
如何让AutoSize为true的label在picturebox上面居中显示
最新推荐文章于 2023-06-10 15:04:57 发布