winfom中listview的drawcolumnheader 怎么画
1个回答
2016-04-13 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517191
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
步骤1:
将ListView的OwnerDraw属性改为True
步骤2:
建立ListView的DawColumnHeader消息函数
步骤3:
代码如下:
private void lsvContactRcd_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
int tColumnCount;
Rectangle tRect = new Rectangle();
Point tPoint=new Point();
Font tFont = new Font("宋体", 9, FontStyle.Regular);
SolidBrush tBackBrush = new SolidBrush(System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))));
SolidBrush tFtontBrush;
tFtontBrush = new SolidBrush (System.Drawing.SystemColors.GradientActiveCaption);
if (lsvContactRcd.Columns.Count == 0)
return;
tColumnCount = lsvContactRcd.Columns.Count;
tRect.Y = 0;
tRect.Height = e.Bounds.Height - 1;
tPoint.Y = 3;
for (int i = 0; i < tColumnCount; i++)
{
if (i == 0)
{
tRect.X = 0;
tRect.Width = lsvContactRcd.Columns[i].Width;
}
else
{
tRect.X += tRect.Width;
tRect.X += 1;
tRect.Width = lsvContactRcd.Columns[i].Width - 1;
}
e.Graphics.FillRectangle(tBackBrush, tRect);
tPoint.X = tRect.X + 3;
e.Graphics.DrawString(lsvContactRcd.Columns[i].Text, tFont, tFtontBrush, tPoint);
}
}
将ListView的OwnerDraw属性改为True
步骤2:
建立ListView的DawColumnHeader消息函数
步骤3:
代码如下:
private void lsvContactRcd_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
int tColumnCount;
Rectangle tRect = new Rectangle();
Point tPoint=new Point();
Font tFont = new Font("宋体", 9, FontStyle.Regular);
SolidBrush tBackBrush = new SolidBrush(System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))));
SolidBrush tFtontBrush;
tFtontBrush = new SolidBrush (System.Drawing.SystemColors.GradientActiveCaption);
if (lsvContactRcd.Columns.Count == 0)
return;
tColumnCount = lsvContactRcd.Columns.Count;
tRect.Y = 0;
tRect.Height = e.Bounds.Height - 1;
tPoint.Y = 3;
for (int i = 0; i < tColumnCount; i++)
{
if (i == 0)
{
tRect.X = 0;
tRect.Width = lsvContactRcd.Columns[i].Width;
}
else
{
tRect.X += tRect.Width;
tRect.X += 1;
tRect.Width = lsvContactRcd.Columns[i].Width - 1;
}
e.Graphics.FillRectangle(tBackBrush, tRect);
tPoint.X = tRect.X + 3;
e.Graphics.DrawString(lsvContactRcd.Columns[i].Text, tFont, tFtontBrush, tPoint);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询