Прочетете на английски Редактиране

Споделяне чрез


DrawItemEventArgs.BackColor Property

Definition

Gets the background color of the item that is being drawn.

C#
public System.Drawing.Color BackColor { get; }

Property Value

The background Color of the item that is being drawn.

Examples

The following code example demonstrates the use of this member. In the example, an event handler reports on the occurrence of the ListBox.DrawItem event. This report helps you learn when the event occurs and can assist you in debugging.

To run the example code, paste it into a project that contains an instance of type ListBox that is named ListBox1. Then make sure that the event handler is associated with the ListBox.DrawItem event.

C#
private void ListBox1_DrawItem(Object sender, DrawItemEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "BackColor", e.BackColor );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Bounds", e.Bounds );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Font", e.Font );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "ForeColor", e.ForeColor );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Graphics", e.Graphics );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Index", e.Index );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "State", e.State );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "DrawItem Event" );
}

Remarks

If the item's state is DrawItemState.Selected, the BackColor is set to SystemColors.HighlightText. If the item's state is not Selected, the BackColor property is set to SystemColors.Window.

Applies to

Продукт Версии
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also