本文介绍了如何设置列标题背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#WinForm中,如何设置DataGridView列标题背景(图像)

In C# WinForm,How to set the DataGridView column header background (Image)

推荐答案


private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            for (int c = 0; c < dataGridView1.ColumnCount; c++)
            {
                if (e.RowIndex < 0&& e.ColumnIndex == c)
                {
                    Font drawFont = new Font("Microsoft Sans Serif", 10);
                    SolidBrush drawBrush = new SolidBrush(Color.Black);

                    e.Graphics.DrawImage(Properties.Resources.title_bg_center, e.CellBounds);
                    e.Graphics.DrawString(dataGridView1.Columns[c].HeaderText, drawFont, drawBrush, e.CellBounds);

                    e.Handled = true;
                    drawBrush.Dispose();
                }
            }
        }


这篇关于如何设置列标题背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:38