繁体   English   中英

DataGridView标头上的自定义标志符号

[英]Custom glyph on DataGridView Header

我有一个DataGridView ,当用户单击它时,我想在列标题上绘制自定义标志符号(假设为三角形)。

我将属性EnableHeadersVisualStyles设置为False

您是否有任何示例或建议如何达到预期效果? 我是否需要从DataGridView或DataGridViewColumn继承?

预先感谢您,Marco

我发现这很有帮助。 它完美地工作

如果要使列标题完美居中,则需要禁用排序。 将列的SortMode属性设置为“ NonSortable”。 每当列文本居中或右对齐时,这都应防止为排序字形保留空间。

来自: 如何将标题居中在DataGridView的列中?

您需要做一些事情,首先将处理程序附加到事件GridView_CellPainting,然后在事件处理程序中执行以下操作

void GridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
                e.PaintBackground( e.ClipBounds, true );
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Near;
                e.Graphics.DrawString( e.FormattedValue.ToString() this.ColumnHeadersDefaultCellStyle.Font, new SolidBrush( this.ColumnHeadersDefaultCellStyle.ForeColor ),e.CellBounds, sf );

                             //
                             //Place code to draw your custom gliph
                             //
                e.Handled = true;
            }
        }

行“ sf.Alignment = StringAlignment.Near;” 如果需要,将文本设置为左对齐

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM