winform开发中:flowLayoutPanel里的内容如何居中显示?
动态计算呗,依据图片宽高
尺寸放大不就居中了
但是图片不固定,有时候一张 ,有时候三张,也有更多的时候,
@大da脸: 尺寸等等又不是不能读取。
@花飘水流兮: 求代码
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { this.panel1.Controls.Clear(); int weith = 200; int high = 200; int interval = Convert.ToInt32(this.numericUpDown1.Value); int pointX = this.panel1.Width / 2 - (weith + interval) * Convert.ToInt32(this.comboBox1.Text) / 2; int pointY = this.panel1.Height / 2 - (high + interval) / 2; for (int i = 0; i < Convert.ToInt32(this.comboBox1.Text); i++) { PictureBox pic = new PictureBox(); string path = AppDomain.CurrentDomain.BaseDirectory + "hj.jpg"; pic.Image = Image.FromFile(path); pic.SizeMode = PictureBoxSizeMode.CenterImage; pic.Size = new Size(weith, high); pic.Location = new Point(pointX, pointY); this.panel1.Controls.Add(pic); pointX += weith + interval; } }
flowLayoutPanel 放到Grid中,不要Fill ,长宽高Auto,然后居中显示就行
Grid?你说的是DataGridView?