![2011062319552722.jpg](https://i-blog.csdnimg.cn/blog_migrate/56da006eca6d0df4df1769b5b01fd3bb.jpeg)
![ContractedBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![ExpandedBlockStart.gif](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
//
改变字体
2 private void btnFont_Click( object sender, EventArgs e)
3 {
4 try
5 {
6 FontDialog fontDialog = new FontDialog();
7 fontDialog.Color = dgvHistroy.RowTemplate.DefaultCellStyle.ForeColor;
8 fontDialog.Font = dgvHistroy.RowTemplate.DefaultCellStyle.Font;
9 fontDialog.AllowScriptChange = true ;
10 if (fontDialog.ShowDialog() != DialogResult.Cancel)
11 {
12 dgvHistroy.RowTemplate.DefaultCellStyle.Font = fontDialog.Font; // 将当前选定的文字改变字体
13 }
14 DataTable ds = (DataTable)dgvHistroy.DataSource;
15 dgvHistroy.DataSource = null ;
16 dgvHistroy.DataSource = ds;
17 dgvHistroy.Columns[ 0 ].Visible = false ;
18 dgvHistroy.Columns[ 1 ].Visible = false ;
19 dgvHistroy.Columns[ 2 ].Visible = false ;
20 dgvHistroy.Columns[ 3 ].Visible = false ;
21 ds.Dispose();
22 }
23 catch { }
24 }
2 private void btnFont_Click( object sender, EventArgs e)
3 {
4 try
5 {
6 FontDialog fontDialog = new FontDialog();
7 fontDialog.Color = dgvHistroy.RowTemplate.DefaultCellStyle.ForeColor;
8 fontDialog.Font = dgvHistroy.RowTemplate.DefaultCellStyle.Font;
9 fontDialog.AllowScriptChange = true ;
10 if (fontDialog.ShowDialog() != DialogResult.Cancel)
11 {
12 dgvHistroy.RowTemplate.DefaultCellStyle.Font = fontDialog.Font; // 将当前选定的文字改变字体
13 }
14 DataTable ds = (DataTable)dgvHistroy.DataSource;
15 dgvHistroy.DataSource = null ;
16 dgvHistroy.DataSource = ds;
17 dgvHistroy.Columns[ 0 ].Visible = false ;
18 dgvHistroy.Columns[ 1 ].Visible = false ;
19 dgvHistroy.Columns[ 2 ].Visible = false ;
20 dgvHistroy.Columns[ 3 ].Visible = false ;
21 ds.Dispose();
22 }
23 catch { }
24 }
如图
调整好想要的字体,点击确定,dataGridView中的字体就会变成想要的字体,很方便的,呵呵!