ListView 第一行标题栏的字体大小和行高怎样设置呢?

解决方案 »

  1.   

    是要设置ListView.View == View.Details时,设置ColumnHeader的字体大小和行高么?如果不是就不用往下看了:)粗看了一下,发现字体是可以设置的,但是行高恐怕有点困难。
    ListView lv = new ListView();
    lv.OwnerDraw = true;
    lv.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(lv_DrawColumnHeader);
    ...    private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
        {
            // 绘制标准背景
            e.DrawBackground();        // 绘制自定义文字
            using (Font headerFont = new Font("Tahoma", 10, FontStyle.Bold))
            {
                e.Graphics.DrawString(e.Header.Text, headerFont,
                    Brushes.Black, e.Bounds, new StringFormat());
            }
            return;
        }
    这里e.Bounds是一个只读属性,表示绘制ColumnHeader时所能操作的矩形范围,这个是Windows产生NM_CUSTOMDRAW是就已经定了的,我对Windows消息机制了解不多,不知道是否有方法来改变这个Bounds的内容,如果能改就可以指定高了。
      

  2.   

    是要设置ListView.View == View.Details时 的行高和字体大小
      

  3.   

    Google了一下,似乎对于ListView还没有太好的解决方案。
    MSDN上也有人提这个问题,得到的答复是使用更高级的DataGridView。我试了一下还不错,可以设置ColumnHeader高度,字体。            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.EnableResizing; //可以改变高度
                this.dataGridView1.ColumnHeadersHeight = 25;
                this.dataGridView1.Columns[0].HeaderCell.Style.Font = new Font("Tahoma", 22);
                this.dataGridView1.Columns[0].HeaderText = "happy everyday";好像不能指定背景图,不过可以自己写一个类,当需要做复杂的效果时            this.dataGridView1.Columns[0].HeaderCell = new OwnerDrawColumnHeader();
    ....
        public class OwnerDrawColumnHeader : DataGridViewColumnHeaderCell
        {
            protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates dataGridViewElementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
            {
                //Do whatever you wants
                graphics.DrawImage(new System.Drawing.Bitmap(@"E:\a.bmp"), new Point(cellBounds.Left, cellBounds.Top));
                graphics.DrawString("lala", new Font("Tahoma", 20), Brushes.Aqua, new PointF(cellBounds.Left + 2, cellBounds.Top + 2));
            }
        }
      

  4.   

    看来 ListView 改变列头没戏了