我正在尝试在 Visual Studio 2008 中将 DataGridView 的列标题设为粗体。
每次我使用属性框将 ColumnHeadersDefaultCellStyle 更改为 Calibri 9.75pt 粗体时,下次重新打开保存的表单时,ColumnHeadersDefaultCellStyle 已恢复为不带粗体的 Calibri 9.75。
我的表单字体是 Calibri 9.75,不带粗体,这是我的默认单元格样式,但我应该能够使用我的 ColumnHeader 样式覆盖默认单元格样式,对吗?
我可以通过在显示表单时设置样式来以编程方式解决此问题,但我们希望 Visual Studio 设计器显示粗体标题,这样我们就可以根据粗体标题文本占用的空间适本地布局列.
此外,实际的设计器文件指定 ColumnHeadersDefaultCellStyle 为粗体,即使设计器界面显示它不是粗体。
dataGridViewCellStyle1.Font = new System.Drawing.Font("Calibri", 9.75F,
System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.receiptDetailView.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle1;
最佳答案
您是否尝试过检查 EnableHeadersVisualStyles 值?
根据MSDN :
If visual styles are enabled and EnableHeadersVisualStyles is set to true, all header cells except the TopLeftHeaderCell are painted using the current theme and the ColumnHeadersDefaultCellStyle values are ignored.
关于winforms - 为什么我的 ColumnHeadersDefaultCellStyle 在 Visual Studio 设计器中不断被重置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11439352/