ListView.DrawColumnHeader Evento
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
public:
event System::Windows::Forms::DrawListViewColumnHeaderEventHandler ^ DrawColumnHeader;
public event System.Windows.Forms.DrawListViewColumnHeaderEventHandler DrawColumnHeader;
public event System.Windows.Forms.DrawListViewColumnHeaderEventHandler? DrawColumnHeader;
member this.DrawColumnHeader : System.Windows.Forms.DrawListViewColumnHeaderEventHandler
Public Custom Event DrawColumnHeader As DrawListViewColumnHeaderEventHandler
Tipo de Evento
Exemplos
O exemplo de código seguinte fornece uma implementação de um DrawColumnHeader gestor de eventos. Para o exemplo completo, incluindo a implementação do DrawSubItem gestor de eventos, veja o OwnerDraw tópico de referência.
// Draws column headers.
private void listView1_DrawColumnHeader(object sender,
DrawListViewColumnHeaderEventArgs e)
{
using (StringFormat sf = new StringFormat())
{
// Store the column text alignment, letting it default
// to Left if it has not been set to Center or Right.
switch (e.Header.TextAlign)
{
case HorizontalAlignment.Center:
sf.Alignment = StringAlignment.Center;
break;
case HorizontalAlignment.Right:
sf.Alignment = StringAlignment.Far;
break;
}
// Draw the standard header background.
e.DrawBackground();
// Draw the header text.
using (Font headerFont =
new Font("Helvetica", 10, FontStyle.Bold))
{
e.Graphics.DrawString(e.Header.Text, headerFont,
Brushes.Black, e.Bounds, sf);
}
}
return;
}
' Draws column headers.
Private Sub listView1_DrawColumnHeader(ByVal sender As Object, _
ByVal e As DrawListViewColumnHeaderEventArgs) _
Handles listView1.DrawColumnHeader
Dim sf As New StringFormat()
Try
' Store the column text alignment, letting it default
' to Left if it has not been set to Center or Right.
Select Case e.Header.TextAlign
Case HorizontalAlignment.Center
sf.Alignment = StringAlignment.Center
Case HorizontalAlignment.Right
sf.Alignment = StringAlignment.Far
End Select
' Draw the standard header background.
e.DrawBackground()
' Draw the header text.
Dim headerFont As New Font("Helvetica", 10, FontStyle.Bold)
Try
e.Graphics.DrawString(e.Header.Text, headerFont, _
Brushes.Black, e.Bounds, sf)
Finally
headerFont.Dispose()
End Try
Finally
sf.Dispose()
End Try
End Sub
Observações
Este evento permite-lhe personalizar a aparência de um ListView controlo usando o desenho do proprietário. Só é aumentada quando a OwnerDraw propriedade está definida como true e a View propriedade está definida como View.Details. Este evento pode ocorrer para cada cabeçalho de coluna no controlo. Para mais informações sobre o desenho do proprietário, consulte o OwnerDraw tópico de referência da propriedade.
Para obter mais informações sobre como manipular eventos, consulte Manipulando e gerando eventos.