C#在调整大小时更改datagridview行的高度 [英] C# change datagridview rows height on resize

查看:193
本文介绍了C#在调整大小时更改datagridview行的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个固定行数和列数的DataGridView



我想要根据整个表单大小更改行高 - 例如,如果我最大化表单,我希望行高度相应增加



我如何实现这一目标? />


谢谢



dj



我尝试过:



处理Resize事件 - 并手动更改所有行高

Hi

I have a DataGridView with fixed number of rows and columns

I want to change the rows height according to the whole form size - for example if i maximize the form i want the rows height to increase accordingly

How can i achieve that?

thanks

dj

What I have tried:

Handling the Resize event - and changing there all the rows heights manually

推荐答案

这很复杂,因为它不是行高的控制因素 - 它是单元格内容大小,通常表示它正在显示的文本的字体大小。

是的,你可以在每次DGV改变时调整单元格的大小,但除非字体大小改变,否则所有这意味着文本在更大的空白区域中显示相同。将字体大小与总DGV大小相匹配并不简单:它们不使用相同的测量单位,因此它根本不是一项简单的工作。



我会看到我是否可以重新考虑这一点:Windows Forms根本不擅长自动调整控件大小,所以重新设计你的用户界面可能比试图让它工作更好,因为总会有是不好看的情况!

WPF非常擅长: wpf - 如何在窗口最大化时按比例调整所有控件的大小? - 堆栈溢出 [ ^ ],只要您仔细选择您的UI元素!
That's complicated, because it's not the row height that is the controlling factor in this - it's the cell content size, which normally means the font size of the text it is displaying.
Yes, you can resize the cells each time the DGV changes, but unless the font size changes, all that means is that the text is displayed the same in a bigger white space. And matching font size to "total DGV size" isn't simple: they don't use the same units of measurement so it isn't a trivial job at all.

I'd see if I could rethink this: Windows Forms isn't good at automatic resizing of controls at all, so redesigning your UI could be a better move than faffing around with trying to get it to work - because there will always be cases when it doesn't look at all good!
WPF is pretty good at it: wpf - How to make all controls resize accordingly proportionally when window is maximized? - Stack Overflow[^] provided you pick your UI elements carefully!


搞定了!



将RowTemplate Resizeable设置为true



然后处理dataGridView resize事件
Got it!

Set the RowTemplate Resizeable to true

and then handling the dataGridView resize event


嗨Dude,



你可以这样付出



Hi Dude ,

You can give like this

dataGridView.RowTemplate.Height = 35;


这篇关于C#在调整大小时更改datagridview行的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆