c# listView 如何设置整格背景色。(winfrom)

qiuzhijun 2010-01-07 11:21:24
如何把文字和图片,整一格设为同一颜色!!
...全文
746 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sztxh 2010-12-22
  • 打赏
  • 举报
回复
这个好像不能实现
h_w_king 2010-01-07
  • 打赏
  • 举报
回复
用listView1_DrawItem, 将文字写到图片上.
参考:


private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{

e.Graphics.DrawImage(e.Item.ImageList.Images[e.Item.ImageIndex], e.Bounds);
e.Graphics.DrawString(e.Item.Text,e.Item.Font,new SolidBrush(e.Item.ForeColor),new Point(e.Bounds.X+5, e.Bounds.Y+50));
}

设置: this.listView1.OwnerDraw = true;
qiuzhijun 2010-01-07
  • 打赏
  • 举报
回复
listView的CellPainting在哪里啊???
qiuzhijun 2010-01-07
  • 打赏
  • 举报
回复
我要把图片和文字,整一块都是同颜色的,因为显示的Items比较多。
wclhack 2010-01-07
  • 打赏
  • 举报
回复
重绘背景色 或者自定义这样的控件
参考如下代码

private void callListDataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if ((e.ColumnIndex == 0) && (e.RowIndex >= 0))
{
// Draw Merged Cell
Graphics g = e.Graphics;
bool selected = ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected);
Color fcolor = (selected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor);
Color bcolor = (selected ? e.CellStyle.SelectionBackColor : e.CellStyle.BackColor);
Font newfont = e.CellStyle.Font;

newfont = new Font(newfont, FontStyle.Bold);

// Get size information
string cust = this.callListDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
string subject = this.callListDataGridView.Rows[e.RowIndex].Cells[1].Value.ToString();
Size newSize = TextRenderer.MeasureText(e.Graphics, cust, newfont);

// Calculate where to draw the content
int x = e.CellBounds.Left + e.CellStyle.Padding.Left;
int y = e.CellBounds.Top + e.CellStyle.Padding.Top;
int width = e.CellBounds.Width - (e.CellStyle.Padding.Left + e.CellStyle.Padding.Right);
int height = newSize.Height + (e.CellStyle.Padding.Top + e.CellStyle.Padding.Bottom);

// Draw background
g.FillRectangle(new SolidBrush(bcolor), e.CellBounds);

// Draw first line
TextRenderer.DrawText(e.Graphics, cust, newfont, new Rectangle(x, y, width, height), fcolor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.EndEllipsis);

// Use grey for second line if not selected
if (!selected)
{
fcolor = Color.Gray;
}

// Reset font and y location
newfont = e.CellStyle.Font;
y = y + height - 2;

TextRenderer.DrawText(e.Graphics, subject, newfont, new Rectangle(x, y, width, height), fcolor, TextFormatFlags.PreserveGraphicsClipping | TextFormatFlags.EndEllipsis);

e.Handled = true;
}
}

kensouterry 2010-01-07
  • 打赏
  • 举报
回复
感觉上面那种效果还比较合适!
lovexilove 2010-01-07
  • 打赏
  • 举报
回复
哪个图片弄大点不知道行不行
zheng2852848 2010-01-07
  • 打赏
  • 举报
回复
这个需要在引用图片之前修改图片的颜色吧。通过程序改颜色?不会。帮顶
qiuzhijun 2010-01-07
  • 打赏
  • 举报
回复
来人啊。
qiuzhijun 2010-01-07
  • 打赏
  • 举报
回复
有人在吗?
huwei001982 2010-01-07
  • 打赏
  • 举报
回复
别用 ListView 啊,呵呵

110,526

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧