DrawItemEventArgs.ForeColor プロパティ

定義

描画されている項目の前景色を取得します。Gets the foreground color of the of the item being drawn.

public:
 property System::Drawing::Color ForeColor { System::Drawing::Color get(); };
public System.Drawing.Color ForeColor { get; }
member this.ForeColor : System.Drawing.Color
Public ReadOnly Property ForeColor As Color

プロパティ値

描画されている項目の前景色を示す ColorThe foreground Color of the item being drawn.

このメンバーの使用例を次のコード例に示します。The following code example demonstrates the use of this member. この例では、イベントハンドラーがListBox.DrawItemイベントの発生を報告します。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.

コード例を実行するには、という名前ListBox ListBox1の型のインスタンスを含むプロジェクトに貼り付けます。To run the example code, paste it into a project that contains an instance of type ListBox that is named ListBox1. 次に、イベントハンドラーがListBox.DrawItemイベントに関連付けられていることを確認します。Then make sure that the event handler is associated with the ListBox.DrawItem event.

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" );
}
Private Sub ListBox1_DrawItem(sender as Object, e as DrawItemEventArgs) _ 
     Handles ListBox1.DrawItem

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

End Sub

注釈

項目の状態がDrawItemState.Selectedの場合ForeColor 、はにSystemColors.HighlightText設定されます。If the item's state is DrawItemState.Selected, the ForeColor is set to SystemColors.HighlightText. 項目の状態がSelected ForeColorでない場合、プロパティはにSystemColors.WindowText設定されます。If the item's state is not Selected, the ForeColor property is set to SystemColors.WindowText.

適用対象

こちらもご覧ください