开发者

How to resize data gridview when the font size changes

I have a datagridview in windows application form below which I put two buttons (one for zoom in and other for zoom out). Now when user press the zoom button I increase/decrease the font size inside the grid according to predefined ratio. It works fine i.e the font size reduces and increases but the only thing that not working is the size of cell or datagridview.

Every time the cell size remai开发者_如何学运维ns fix. I want to resize my datagridview accordingly, currently i am using the following code but it doesn't work in my case :(

dataGridView1.AutoResizeColumns();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

Note: my datagridview always contains text in it. So no need to consider other options like what if there is a button/label in a cell etc.


you should either switch the two lines:

dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
dataGridView1.AutoResizeColumns();

Or call it like this:

dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);

Either way you have to do this after you have changed the font.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜