C# WinForms DataGridView 字体大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/64041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WinForms DataGridView font size
提问by leora
How do I change font size on the DataGridView?
如何更改 DataGridView 上的字体大小?
采纳答案by psamwel
private void UpdateFont()
{
//Change cell font
foreach(DataGridViewColumn c in dgAssets.Columns)
{
c.DefaultCellStyle.Font = new Font("Arial", 8.5F, GraphicsUnit.Pixel);
}
}
回答by Espo
Use the Font-property on the gridview. See MSDN for details and samples:
使用 gridview 上的字体属性。有关详细信息和示例,请参阅 MSDN:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.font.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.font.aspx
回答by Merin Nakarmi
In winform datagrid, right click to view its properties. It has a property called DefaultCellStyle. Click the ellipsis on DefaultCellStyle, then it will present Cell Style Builder window which has the option to change the font size.
在winform datagrid中,右击查看其属性。它有一个名为 DefaultCellStyle 的属性。单击 DefaultCellStyle 上的省略号,将显示 Cell Style Builder 窗口,该窗口具有更改字体大小的选项。
Its easy.
这很简单。
回答by sankalp korde
Go to designer.cs file of the form in which you have the grid view and comment the following line: - //this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
转到具有网格视图的表单的designer.cs 文件并注释以下行: - //this.dataGridView1.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1;
if you are using vs 2008 or .net framework 3.5 as it will be by default applied to alternating rows.
如果您使用的是 vs 2008 或 .net framework 3.5,因为它将默认应用于交替行。
回答by Sylvio
' Cell style
With .DefaultCellStyle
.BackColor = Color.Black
.ForeColor = Color.White
.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.0!,
System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
.Alignment = DataGridViewContentAlignment.MiddleRight
End With
回答by CVKrishna
I too experienced same problem in the DataGridView but figured out that the DefaultCell style was inheriting the font of the groupbox (Datagrid is placed in groupbox). So changing the font of the groupbox changed the DefaultCellStyle too.
我在 DataGridView 中也遇到了同样的问题,但发现 DefaultCell 样式继承了 groupbox 的字体(Datagrid 放在 groupbox 中)。所以改变 groupbox 的字体也改变了 DefaultCellStyle。
Regards
问候
回答by Ashraf Abusada
The straight forward approach:
直接的方法:
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 15);
回答by Sheraz Latif
1st Step:Go to the form where datagridview is added
第一步:进入添加datagridview的表单
2nd step:click on the datagridview at the top right side there will be displayed a small button of like play icon or arrow to edit the datagridview.
第二步:点击右上角的datagridview,会显示一个类似播放图标或箭头的小按钮来编辑datagridview。
3rd step:click on that button and select edit columns now click the attributes you want to increase font size.
第 3 步:单击该按钮并选择编辑列现在单击要增加字体大小的属性。
4th step:on the right side of the property menu the first on the list column named defaultcellstyle click on its property a new window will open to change the font and font size.
第 4 步:在属性菜单右侧的第一个名为 defaultcellstyle 的列表列上单击其属性,将打开一个新窗口以更改字体和字体大小。
回答by Niraj Trivedi
For changing particular single column font size use following statement
要更改特定的单列字体大小,请使用以下语句
DataGridView.Columns[1].DefaultCellStyle.Font = new Font("Verdana", 16, FontStyle.Bold);
DataGridView.Columns[1].DefaultCellStyle.Font = new Font("Verdana", 16, FontStyle.Bold);
回答by Mahmut K.
I think it's easiest:
我认为这是最简单的:
First set any Label as you like (Italic, Bold, Size etc.) And:
首先根据需要设置任何标签(斜体、粗体、大小等)并且:
yourDataGridView.Font = anyLabel.Font;