Comment changer la forecolor de tête listview? Application Windows forme
-
27-10-2019 - |
Question
Je sais que je peux changer la propriété OwnerDraw
à true
puis gérer l'événement DrawColumnHeader
mais si je le fais comme ça, je dois prendre soin de tout dans l'en-tête de dessin.
Y at-il de toute façon que je viens de changer la couleur de premier plan et tout le reste est dessiné par défaut?
La solution
Que diriez-vous ceci:
Créer un nouveau projet WinForm, faites glisser un ListView contrôle sur la forme, ensemble OwnerDraw = true , Voir = Détails dans le volet Propriétés , puis gérer la DrawColumnHeader événement.
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();
}
}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow