¿Cómo cambiar el pronóstico del encabezado de ListView? Aplicación de formulario C# Windows

StackOverflow https://stackoverflow.com/questions/8818224

Pregunta

Sé que puedo cambiar el OwnerDraw propiedad de true y luego manejar el DrawColumnHeader Evento, pero si lo hago así, tengo que cuidar todo al dibujar el encabezado.

¿Hay de todos modos que solo cambie el color de primer plano y todo lo demás se dibuja con valores predeterminados?

¿Fue útil?

Solución

Qué tal esto:

Crear un nuevo proyecto WinForm, arrastre un Vista de la lista controlar el formulario, establecer Propietario de propietario = verdadero, Ver = Detalles En el panel de propiedades, luego maneje el Cabezal 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();
        }
    }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top