100分!!WinForm下加个FlowLayoutPanel容器,容器里面再放个DataGridView,如何让DataGridView自适应大小呢?
WinForm下加个FlowLayoutPanel容器,容器里面再放个DataGridView,如何让DataGridView自适应大小呢?
就是当Form窗口伸缩,变大变小,这个DataGridView也跟着伸缩,变大变小??
flowLayoutPanel1下,anchor不管用啊~~~
[解决办法]
使用你主窗口的resize事件,在那里面写上你datagrid的大小。
[解决办法]
在Form_Resize或SizeChanged事件里设置位置
没用FlowLayoutPanel,Anchor和Dock可以处理
[解决办法]
你直接在Form里面放个DataGridView控件,然后将DataGridView的Dock设为fill.你试试.
或者在窗体的resize事件里写:
DataGridView.width = this.width;
DataGridView.height = this.height;
DataGridView.top = 0;
DataGridView.left = 0;
[解决办法]
- C# code
//下面的代码在一个窗体了放了一个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属性,要两个都设置
你再试试.不需要单独再在事件里写了
我刚试了,你说的问题不存在.