日期:2014-05-18 浏览次数:21241 次
//下面的代码在一个窗体了放了一个flowLayoutPanel和一个dataGridView控件已经测试成功.
//FlowLayoutPanel,DataGridView的dock属性都不设置,也就是默认值none
private void Form1_Load(object sender, EventArgs e)
{
this.flowLayoutPanel1.Height = this.Height;
this.flowLayoutPanel1.Width = this.Width;
this.flowLayoutPanel1.Top = 0;
this.flowLayoutPanel1.Left = 0;
//这里的dataGridView1的高度和宽度减去的数值是为了保证,dataGridView1出现滚动条.
this.dataGridView1.Height = this.flowLayoutPanel1.Height-40;
this.dataGridView1.Width = this.flowLayoutPanel1.Width - 15;
this.dataGridView1.Top = 0;
this.dataGridView1.Left = 0;
}
private void Form1_Resize(object sender, EventArgs e)
{
this.flowLayoutPanel1.Height = this.Height;
this.flowLayoutPanel1.Width = this.Width;
this.dataGridView1.Height = this.flowLayoutPanel1.Height - 40;
this.dataGridView1.Width = this.flowLayoutPanel1.Width - 15;
}
------解决方案--------------------
你必须设置flowLayoutPanel和dataGridView的Anchor属性,要两个都设置
你再试试.不需要单独再在事件里写了
我刚试了,你说的问题不存在.