ListView的问题 各位牛人帮帮忙

SunSiShuXu 2009-05-24 07:44:51
ListViewItemCx itm = e.Item as ListViewItemCx;
Rectangle itemRect = e.Bounds;
if ((e.State & ListViewItemStates.Selected) != 0)
{
e.Graphics.FillRectangle(Brushes.LightPink, itemRect);
e.DrawFocusRectangle();
}
else
{

using (SolidBrush brush =
new SolidBrush(Color.White))
{
e.Graphics.FillRectangle(brush, itemRect);
}


}

try
{

int idx = itm.Index;
Image img = LargeImageList.Images[idx];
Point mg = new Point();
Size isz = Constants.UISize.thumbnailSize;
mg.X = (int)((itemRect.Width - isz.Width) / 2);
mg.Y = (int)((itemRect.Height - isz.Height) / 2);
Rectangle rect = new Rectangle(itemRect.X + mg.X, itemRect.Y, isz.Width, isz.Height);


if (itm.IsDirectory)
{
mg = new Point();
isz = Constants.UISize.largeIconSize;
mg.X = (int)((rect.Width - isz.Width) / 2);
mg.Y = (int)((rect.Height - isz.Height) / 2);
Rectangle iconBound = new Rectangle(rect.Left + mg.X, rect.Top + mg.Y, isz.Width, isz.Height);
e.Graphics.DrawImage(img, iconBound);

}
else
{
mg = new Point();
isz = img.Size;
mg.X = (int)((rect.Width - isz.Width) / 2);
mg.Y = (int)((rect.Height - isz.Height) / 2);
Rectangle imgBound = new Rectangle(rect.Left + mg.X, rect.Top + mg.Y, isz.Width, isz.Height);
e.Graphics.DrawImage(img, imgBound);
}
e.Graphics.DrawRectangle(new Pen(Color.Red), rect);

if ((e.State & ListViewItemStates.Selected) != 0)
{
e.DrawText(TextFormatFlags.Bottom | TextFormatFlags.HorizontalCenter | TextFormatFlags.WordBreak);
}
else
{

string str = LimitLengthString(e.Item.Text, e.Item.Font, rect.Width);
SizeF sf = e.Graphics.MeasureString(str, e.Item.Font);

Point textPos = new Point();
textPos.X = rect.X + (int)((rect.Width - sf.Width) / 2);
textPos.Y = rect.Bottom + 10;
e.Graphics.DrawString(str, e.Item.Font, new SolidBrush(Color.Black), textPos);
}


}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}

各位 我的重新绘画的这个listView的图片显示方式 这个画出来之后浓缩图是按正常显示 可是像图标,列表 什么的布局都是乱的 各位给看看
应该怎样改 能让 几种显示方式都能正常显示
...全文
163 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
SunSiShuXu 2009-05-25
  • 打赏
  • 举报
回复
各位帮帮忙啊

我现在急用啊 如果分不够可以说话 各位帮帮忙啊
修改一下昵称 2009-05-24
  • 打赏
  • 举报
回复
路过帮顶...ing
bw555 2009-05-24
  • 打赏
  • 举报
回复
哎,家里机器没环境,没法测试了
zcandyly20211 2009-05-24
  • 打赏
  • 举报
回复
友情up!
gciyfzx07 2009-05-24
  • 打赏
  • 举报
回复
up
光宇广贞 2009-05-24
  • 打赏
  • 举报
回复
同学,你自己画吗?

listview里面你去listviewitem类的重载啊!上MSDN上查。你想加小图像,大图像等等,listviewitem的重载里面都有。

没有用listview还去画的。那用listview干嘛……
fdc123 2009-05-24
  • 打赏
  • 举报
回复
up!
全速前行 2009-05-24
  • 打赏
  • 举报
回复
没有环境美法帮测啊~~~
顶下!
gengxin_914 2009-05-24
  • 打赏
  • 举报
回复
up
麻子Mozart 2009-05-24
  • 打赏
  • 举报
回复
up
qzw4549689 2009-05-24
  • 打赏
  • 举报
回复
帮顶下
xiangbupingfan 2009-05-24
  • 打赏
  • 举报
回复
不会,还是帮顶了

110,567

社区成员

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

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

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