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的图片显示方式 这个画出来之后浓缩图是按正常显示 可是像图标,列表 什么的布局都是乱的 各位给看看
应该怎样改 能让 几种显示方式都能正常显示
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的图片显示方式 这个画出来之后浓缩图是按正常显示 可是像图标,列表 什么的布局都是乱的 各位给看看
应该怎样改 能让 几种显示方式都能正常显示
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货