DrawListViewItemEventArgs.Graphics プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

ListViewItem の描画に使用する Graphics。


ListView コントロールのカスタム描画を提供するアプリケーションで、Graphics プロパティを使用する方法を次のコード例に示します。この例では、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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からDrawListViewItemEventArgs.Graphics プロパティを検索する場合は、下記のリンクをクリックしてください。

- DrawListViewItemEventArgs.Graphics プロパティのページへのリンク