Gra*_*ian 10
您不能只是覆盖该OnPaint()方法.该方法在ListView中不执行任何操作.同样,OwnerDrawn允许您自定义绘制每个单元格,但不允许您作为整体绘制控件.
使用ObjectListView(围绕.NET WinForms ListView的开源包装器)并使用其Overlay功能.这让你毫不费力地做这样的事情:
ListView上的文本http://i37.tinypic.com/29zwu1d.jpg
这是由以下代码生成的:
this.olv1.OverlayText.Alignment = ContentAlignment.BottomRight;
this.olv1.OverlayText.Text = "Trial version";
this.olv1.OverlayText.BackColor = Color.White;
this.olv1.OverlayText.BorderWidth = 2.0f;
this.olv1.OverlayText.BorderColor = Color.RoyalBlue;
this.olv1.OverlayText.TextColor = Color.DarkBlue;
Run Code Online (Sandbox Code Playgroud)
class MyCustomlistView : ListView
{
public MyCustomlistView()
: base()
{
SetStyle(ControlStyles.UserPaint, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawString("This is a custom string", new Font(FontFamily.GenericSerif, 10, FontStyle.Bold), Brushes.Black, new PointF(0, 50));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16092 次 |
| 最近记录: |