Winforms 子类ListView列0在Windows 7上显示损坏的文本

Winforms 子类ListView列0在Windows 7上显示损坏的文本,winforms,Winforms,Windows 7(64位)、.NET 4(32位应用程序) 我有一个子类System.Windows.Forms.ListView,其中显示了两列 在“详细信息”视图中。只涉及文本字段。名单上有大约100人 排。在初始显示时,所有字段均清晰绘制,但在滚动或 使用滚动条“分页”,第一列中某些字段的文本变为 不可读。它似乎被随机线条和斑点覆盖 我能做些什么来确保文本清楚地绘制在第0列中 当跨网络使用远程桌面时,效果会减弱(清晰度提高) 局域网。 使用远程桌面时,效果消失(所有文本均清晰绘制) 穿过

Windows 7(64位)、.NET 4(32位应用程序)

我有一个子类System.Windows.Forms.ListView,其中显示了两列 在“详细信息”视图中。只涉及文本字段。名单上有大约100人 排。在初始显示时,所有字段均清晰绘制,但在滚动或 使用滚动条“分页”,第一列中某些字段的文本变为 不可读。它似乎被随机线条和斑点覆盖

我能做些什么来确保文本清楚地绘制在第0列中

当跨网络使用远程桌面时,效果会减弱(清晰度提高) 局域网。 使用远程桌面时,效果消失(所有文本均清晰绘制) 穿过一个海湾

ListView始终完美地绘制在Windows XP上

为了简化测试,将引入列标题和DrawItem调用。问题区域是包含代码的子项

protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
{
    using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap))
    {
        Rectangle rect = new Rectangle(e.Bounds.Left
          ,e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
        e.Graphics.DrawString(e.SubItem.Text, this.Font, Brushes.Black
          ,rect, sf);
    }
    base.OnDrawSubItem(e);
}
以下是再现问题的完整代码:

using System;
using System.Windows.Forms;
using System.Drawing;
///
/// Build by saving to a file called LVTrial.cs and then executing "csc LVTrial.cs"
/// Scroll list up and down on a windows 7 box and the first column of text is corrupted.
///

class MyListView : ListView
{
    Random randomiser = new Random();
    private const int NUM_ROWS = 100;
    private const int NUM_COLS = 2;
    public MyListView()
    {
        this.Location = new System.Drawing.Point(23, 25);
        this.OwnerDraw = true;
        this.Size = new System.Drawing.Size(625, 387);
        this.TabIndex = 0;
        this.UseCompatibleStateImageBehavior = false;
        this.View = System.Windows.Forms.View.Details;
        for (int ii = 0; ii < NUM_COLS; ii++)
        {
            this.Columns.Add((
              (System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())));
        }
        for (int ii = 0; ii < NUM_ROWS; ii++)
        {
            this.Items.Add( new ListViewItem( 
              new string[NUM_COLS] { CreateRandomString(1, 6), CreateRandomString(1, 6) } ) );
        }
    }
    protected override void OnDrawSubItem(DrawListViewSubItemEventArgs e)
    {
        using (StringFormat sf = new StringFormat(StringFormatFlags.NoWrap))
        {
            Rectangle rect = new Rectangle(e.Bounds.Left
              ,e.Bounds.Top, e.Bounds.Width, e.Bounds.Height);
            e.Graphics.DrawString(e.SubItem.Text, this.Font, Brushes.Black
              ,rect, sf);
        }
        base.OnDrawSubItem(e);
    }
    private string CreateRandomString(int minLength, int maxLength)
    {
        string str = string.Empty;
        int length = randomiser.Next(minLength, maxLength + 1);
        for (int ii = 0; ii < length; ii++)
        {
            int asciiChar = randomiser.Next(32, 126);   // ascii range
            str += Convert.ToChar(asciiChar);
        }
        return str;
    }
}

class LVTrial : Form
{
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new LVTrial());
    }
    private LVTrial()
    {
        MyListView myListView = new MyListView();
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(674, 440);
        this.Controls.Add(myListView);
        this.Text = "LVTrial";
    }
}
使用系统;
使用System.Windows.Forms;
使用系统图;
///
///通过保存到名为LVTrial.cs的文件,然后执行“csc LVTrial.cs”来构建
///在windows 7框上上下滚动列表,第一列文本已损坏。
///
类MyListView:ListView
{
Random randomiser=新的Random();
私有const int NUM_ROWS=100;
私有常量int NUM_COLS=2;
公共MyListView()
{
该位置=新系统图纸点(23,25);
this.OwnerDraw=true;
该尺寸=新系统图纸尺寸(625387);
该指数=0;
this.UseCompatibleStateImageBehavior=false;
this.View=System.Windows.Forms.View.Details;
对于(int ii=0;ii
我已将此记录为Windows 7的错误

我自己的解决方法是在位置0处插入一个附加列。现在,我在第0列中为每个项目绘制一个带有透明笔刷的矩形。所有这些都会阻止右侧列中的文本被绘制损坏。我想象画一幅图像也能达到同样的效果,但我还没有尝试过。您不能隐藏此虚拟列,因为问题只会转移到第二列(即第一个可见的coolumn)

另一个提示是,它似乎与性能有关。列表视图中的100项比10000项更有可能出现此错误