ListView 第一行标题栏的字体大小和行高怎样设置呢? ListView 第一行标题栏的字体大小和行高怎样设置呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 是要设置ListView.View == View.Details时,设置ColumnHeader的字体大小和行高么?如果不是就不用往下看了:)粗看了一下,发现字体是可以设置的,但是行高恐怕有点困难。ListView lv = new ListView();lv.OwnerDraw = true;lv.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(lv_DrawColumnHeader);... private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { // 绘制标准背景 e.DrawBackground(); // 绘制自定义文字 using (Font headerFont = new Font("Tahoma", 10, FontStyle.Bold)) { e.Graphics.DrawString(e.Header.Text, headerFont, Brushes.Black, e.Bounds, new StringFormat()); } return; }这里e.Bounds是一个只读属性,表示绘制ColumnHeader时所能操作的矩形范围,这个是Windows产生NM_CUSTOMDRAW是就已经定了的,我对Windows消息机制了解不多,不知道是否有方法来改变这个Bounds的内容,如果能改就可以指定高了。 是要设置ListView.View == View.Details时 的行高和字体大小 Google了一下,似乎对于ListView还没有太好的解决方案。MSDN上也有人提这个问题,得到的答复是使用更高级的DataGridView。我试了一下还不错,可以设置ColumnHeader高度,字体。 this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; //可以改变高度 this.dataGridView1.ColumnHeadersHeight = 25; this.dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Tahoma", 22); this.dataGridView1.Columns[0].HeaderText = "happy everyday";好像不能指定背景图,不过可以自己写一个类,当需要做复杂的效果时 this.dataGridView1.Columns[0].HeaderCell = new OwnerDrawColumnHeader();.... public class OwnerDrawColumnHeader : DataGridViewColumnHeaderCell { protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { //Do whatever you wants graphics.DrawImage(new System.Drawing.Bitmap(@"E:\a.bmp"), new Point(cellBounds.Left, cellBounds.Top)); graphics.DrawString("lala", new Font("Tahoma", 20), Brushes.Aqua, new PointF(cellBounds.Left + 2, cellBounds.Top + 2)); } } 看来 ListView 改变列头没戏了 请问,如何做插件 怎样实现自己的Control基类 截取字符串 怎么取得与变量相关的文本框的ID,也就是说怎么把一个变量赋给文本框的ID? 序列化途径 怎么把拷贝的excel内容存到数据库里呢? 我想知道如何判断打印机的缺纸状态,以及当中的打印任务是否完成还是卡纸这类情况 C#2005中的DataGirdView问题,小弟在线等! 跪求高人帮忙~服务器的帐号被挺用了 如何将文本打印到指定的位置??? 如何在水晶报表打印的时候,代码修改打印机默认纸张? 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 202.104.236.110:80
ListView lv = new ListView();
lv.OwnerDraw = true;
lv.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(lv_DrawColumnHeader);
... private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
// 绘制标准背景
e.DrawBackground(); // 绘制自定义文字
using (Font headerFont = new Font("Tahoma", 10, FontStyle.Bold))
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, new StringFormat());
}
return;
}
这里e.Bounds是一个只读属性,表示绘制ColumnHeader时所能操作的矩形范围,这个是Windows产生NM_CUSTOMDRAW是就已经定了的,我对Windows消息机制了解不多,不知道是否有方法来改变这个Bounds的内容,如果能改就可以指定高了。
MSDN上也有人提这个问题,得到的答复是使用更高级的DataGridView。我试了一下还不错,可以设置ColumnHeader高度,字体。 this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; //可以改变高度
this.dataGridView1.ColumnHeadersHeight = 25;
this.dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Tahoma", 22);
this.dataGridView1.Columns[0].HeaderText = "happy everyday";好像不能指定背景图,不过可以自己写一个类,当需要做复杂的效果时 this.dataGridView1.Columns[0].HeaderCell = new OwnerDrawColumnHeader();
....
public class OwnerDrawColumnHeader : DataGridViewColumnHeaderCell
{
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
{
//Do whatever you wants
graphics.DrawImage(new System.Drawing.Bitmap(@"E:\a.bmp"), new Point(cellBounds.Left, cellBounds.Top));
graphics.DrawString("lala", new Font("Tahoma", 20), Brushes.Aqua, new PointF(cellBounds.Left + 2, cellBounds.Top + 2));
}
}