【问题标题】:WinForms ListView Details Column Rendering Issue [duplicate]WinForms ListView详细信息列渲染问题[重复]
【发布时间】:2016-10-09 04:57:40
【问题描述】:

我有一个简单的 WinForms ListView,它设置为在 Details 视图中显示一些项目。

也许这是一个很容易解决的众所周知的问题,但我似乎无法让它看起来正确:

列网格线略有偏离。

以下是相关代码:

partial class MainForm
{
    private void InitializeComponent()
    {
        this.listView = new System.Windows.Forms.ListView();
        this.SuspendLayout();
        // 
        // listView
        // 
        this.listView.FullRowSelect = true;
        this.listView.GridLines = true;
        this.listView.Location = new System.Drawing.Point(13, 13);
        this.listView.MultiSelect = false;
        this.listView.Name = "listView";
        this.listView.Size = new System.Drawing.Size(539, 150);
        this.listView.TabIndex = 0;
        this.listView.UseCompatibleStateImageBehavior = false;
        this.listView.View = System.Windows.Forms.View.Details;
        // 
        // MainForm
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(564, 185);
        this.Controls.Add(this.listView);
        this.Name = "MainForm";
        this.Text = "Main Form";
        this.ResumeLayout(false);
    }

    private System.Windows.Forms.ListView listView;
}

有人看过吗?我之前没有使用过 ListView 控件,但是我在 Internet 上注意到了很多关于它的问题。不过,我还没有发现任何关于这个问题的具体信息。

注意:很遗憾,我无法使用任何第三方控件作为解决方案,只能使用标准的 WinForms。

【问题讨论】:

  • 据我所知,这是一个已知的错误。不确定是否值得owner-drawing the control..
  • @TaW Owner-drawing 修复了对齐,谢谢!但是,listView_ColumnClick() 事件中没有显示我拥有的排序图像。代码与此类似:listView.Columns["Name"].ImageKey = SortDirection.Ascending;(是的,listView.LargeImageListlistView.SmallImageList 已正确设置)。我想我应该在listView_DrawColumnHeader() 事件处理程序中使用visualStyleRenderer.DrawText() 以外的东西?任何帮助将不胜感激。
  • 我已经用几行更新了另一个答案以包含图像。试试看对你有没有用..
  • 为了在渲染时获得更好的效果,可以使用VisualStyleRenderer。我用它在链接的答案中绘制ColumnHeader。您也可以使用它来绘制排序字形。例如var sortRenderer = new VisualStyleRenderer(VisualStyleElement.Header.SortArrow.SortedDown); 并绘制与在链接帖子中绘制列标题相同的字形。
  • @SameerSingh 我在链接帖子中编辑了答案,以包含排序字形的呈现,并将问题作为完全重复项关闭。

标签: c# winforms listview


【解决方案1】:

您应该对多列使用 DatagridView 控件,否则请查看此链接 http://csharp.net-informations.com/gui/cs-listview.htm ;)

【讨论】:

    猜你喜欢
    • 2011-11-01
    • 1970-01-01
    • 2014-12-15
    • 2019-03-25
    • 1970-01-01
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    相关资源
    最近更新 更多