【文件属性】:
文件名称:C# WinForm控件美化扩展系列之ListView
文件大小:161KB
文件格式:RAR
更新时间:2013-06-29 09:32:20
c#
前面的一篇文章C# WinForm控件美化扩展系列之ListView(2)中,存在列表项文本错乱的问题,这是因为绘制文本的时候不小心选错了一个属性,把SubItem选成了Item,所以总会得到了第一项的文本。除了修正这个错误外,对列表项选中后的背景画法进行了改变,使得选中的列表项不在是每个子项都有一个矩形边框,而是全部只有一个矩形边框。另外,实现了对ListView的边框的重绘,可以轻易的更换边框颜色。
如下:
private void WmNcPaint(ref Message m)
{
base.WndProc(ref m);
if (base.BorderStyle == BorderStyle.None)
{
return;
}
IntPtr hDC = NativeMethods.GetWindowDC(m.HWnd);
if (hDC == IntPtr.Zero)
{
throw new Win32Exception();
}
try
{
Color backColor = BackColor;
Color borderColor = _borderColor;
Rectangle bounds = new Rectangle(0, 0, Width, Height);
using (Graphics g = Graphics.FromHdc(hDC))
{
using (Region region = new Region(bounds))
{
region.Exclude(AbsoluteClientRectangle);
using (Brush brush = new SolidBrush(backColor))
{
g.FillRegion(brush, region);
}
}
ControlPaint.DrawBorder(
g,
bounds,
borderColor,
ButtonBorderStyle.Solid);
}
}
finally
{
NativeMethods.ReleaseDC(m.HWnd, hDC);
}
m.Result = IntPtr.Zero;
}
【文件预览】:
ListViewExDemo-2
----ListViewEx()
--------bin()
--------obj()
--------Properties()
--------ListViewEx.csproj(3KB)
--------ListViewEx.cs(22KB)
--------NativeMethods.cs(11KB)
----ListViewExDemo.suo(27KB)
----ListViewExDemo1.png(18KB)
----ListViewExDemo2.png(21KB)
----Thumbs.db(5KB)
----ListViewExDemo.sln(1KB)
----ListViewExDemo()
--------Form1.cs(584B)
--------bin()
--------obj()
--------Properties()
--------Program.cs(473B)
--------Form1.Designer.cs(8KB)
--------Form1.resx(20KB)
--------ListViewExDemo.csproj(3KB)
网友评论
- 东西不错,参考价值不小
- 不错的资源,能运行;但还有点小BUG,需要调整下
- 非常不错,可以自己在此基础上做一些改动,达到自己想要的效果
- 很不错的东西啊,谢谢。
- 不错,比较完美
- 非常不错,是我一直要找的资源
- 不错,比较完美
- 不错能运行,不错的资源
- 很不错美化的很好,完全学习了
- 能运行,不错的资源
- 经测试能运行,但是有bug
- 经测试能运行,不错的资源
- 只是部分源码开放
- 能运行,不错的资源
- 代码不能运行。。只能参考