Domanda

So che posso cambiare la proprietà OwnerDraw per true e poi gestire l'evento DrawColumnHeader, ma se lo faccio come questo, devo prendere cura di tutto nel disegno nell'intestazione.

Esiste un modo che mi limito a cambiare il colore di primo piano e tutto il resto è disegnato con le impostazioni predefinite?

È stato utile?

Soluzione

Che ne dite di questo:

Creare un nuovo progetto WinForm, trascinare un ListView di controllo nel form, insieme OwnerDraw = true , Visualizza = dettagli nel riquadro Proprietà , quindi gestire il DrawColumnHeader evento.

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            this.SetLastColumnWidth();

            this.theListView.Layout += delegate
            {
                this.SetLastColumnWidth();
            };
        }

        private void SetLastColumnWidth()
        {
            // Force the last ListView column width to occupy all the
            // available space.
            this.theListView.Columns[ this.theListView.Columns.Count - 1 ].Width = -2;
        }

        private void listView1_DrawColumnHeader( object sender, DrawListViewColumnHeaderEventArgs e )
        {
            // Fill header background with solid yello color.
            e.Graphics.FillRectangle( Brushes.Yellow, e.Bounds );
            // Let ListView draw everything else.
            e.DrawText();
        }
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top