DrawListViewItemEventArgs.State プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DrawListViewItemEventArgs.State プロパティの意味・解説 

DrawListViewItemEventArgs.State プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

描画する ListViewItem の現在の状態取得します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Dim instance As DrawListViewItemEventArgs
Dim value As ListViewItemStates

value = instance.State
public ListViewItemStates State { get; }
public:
property ListViewItemStates State {
    ListViewItemStates get ();
}
/** @property */
public ListViewItemStates get_State ()
public function get State
 () : ListViewItemStates

プロパティ
ListViewItem現在の状態を示す ListViewItemStates 値のビットごとの組み合わせ

解説解説
使用例使用例

ListView コントロールカスタム描画提供するアプリケーションで、State プロパティ使用する方法次のコード例示します。この例では、ListView.DrawItem イベントハンドラは項目全体背景描画ます。詳細ビュー以外のすべてのビューでは、このハンドラによって前景テキスト描画されます。詳細ビューでは、ListView.DrawSubItem イベント前景テキスト描画されます。

コード全体については、DrawListViewItemEventArgs の概要リファレンス トピック参照してください

' Draws the backgrounds for entire ListView items.
Private Sub listView1_DrawItem(ByVal
 sender As Object, _
    ByVal e As DrawListViewItemEventArgs) _
    Handles listView1.DrawItem

    If Not (e.State And
 ListViewItemStates.Selected) = 0 Then

        ' Draw the background for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds)
        e.DrawFocusRectangle()

    Else

        ' Draw the background for an unselected item.
        Dim brush As New
 LinearGradientBrush(e.Bounds, Color.Orange, _
            Color.Maroon, LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(brush, e.Bounds)
        Finally
            brush.Dispose()
        End Try

    End If

    ' Draw the item text for views other than the Details view.
    If Not Me.listView1.View
 = View.Details Then
        e.DrawText()
    End If

End Sub
// Draws the backgrounds for entire ListView items.
private void listView1_DrawItem(object sender
,
    DrawListViewItemEventArgs e)
{
    if ((e.State & ListViewItemStates.Selected) != 0)
    {
        // Draw the background and focus rectangle for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
        e.DrawFocusRectangle();
    }
    else
    {
        // Draw the background for an unselected item.
        using (LinearGradientBrush brush =
            new LinearGradientBrush(e.Bounds, Color.Orange,
            Color.Maroon, LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(brush, e.Bounds);
        }
    }

    // Draw the item text for views other than the Details view.
    if (listView1.View != View.Details)
    {
        e.DrawText();
    }
}
   // Draws the backgrounds for entire ListView items.
private:
   void listView1_DrawItem( Object^ /*sender*/, DrawListViewItemEventArgs^
 e )
   {
      if ( (e->State & ListViewItemStates::Selected) !=
 (ListViewItemStates)0 )
      {
         // Draw the background for a selected item.
         e->Graphics->FillRectangle( Brushes::Maroon, e->Bounds );
         e->DrawFocusRectangle();
      }
      else
      {
         // Draw the background for an unselected item.
         LinearGradientBrush^ myBrush = gcnew LinearGradientBrush( e->Bounds,Color::Orange,Color::Maroon,LinearGradientMode::Horizontal
 );
         try
         {
            e->Graphics->FillRectangle( myBrush, e->Bounds );
         }
         finally
         {
            if ( myBrush )
               delete (IDisposable^)myBrush;
         }
      }

      if ( listView1->View != View::Details )
      {
         e->DrawText();
      }
   }
// Draws the backgrounds for the column header row and for entire
// ListView items.
private void myListView_DrawItem(Object sender,
 DrawListViewItemEventArgs e)
{
    // Draw the background for the column header row.
    if (e.get_ItemIndex() == -1) {
        e.get_Item().set_BackColor(Color.get_Black());
        e.DrawBackground();
    }
    // Draw the background for a selected item.
    else {
        if (Convert.ToInt32((e.get_State() & ListViewItemStates.Selected))
            != 0) {
            e.get_Graphics().FillRectangle(Brushes.get_Maroon(),
                e.get_Bounds());
            e.DrawFocusRectangle();
        }
        // Draw the background for an unselected item.
        else {
            LinearGradientBrush myBrush = new LinearGradientBrush(
                e.get_Bounds(), Color.get_Orange(), Color.get_Maroon(),
                LinearGradientMode.Horizontal);
            try {
                e.get_Graphics().FillRectangle(myBrush, e.get_Bounds());
            }
            finally {
                myBrush.Dispose();
            }    
        }
    }
    // Draw the item text for views other than the Details view.
    if (!(((ListView)sender).get_View().Equals(View.Details)))
 {
        e.DrawText();
    }
} //myListView_DrawItem
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DrawListViewItemEventArgs クラス
DrawListViewItemEventArgs メンバ
System.Windows.Forms 名前空間
DrawListViewItemEventArgs.Item プロパティ
ListView
ListView.DrawItem
ListViewItem
ListViewItemStates


このページでは「.NET Framework クラス ライブラリ リファレンス」からDrawListViewItemEventArgs.State プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からDrawListViewItemEventArgs.State プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からDrawListViewItemEventArgs.State プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DrawListViewItemEventArgs.State プロパティ」の関連用語

DrawListViewItemEventArgs.State プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DrawListViewItemEventArgs.State プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS