DataGridViewRowPostPaintEventArgs.DrawFocus メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewRowPostPaintEventArgs.DrawFocus メソッドの意味・解説 

DataGridViewRowPostPaintEventArgs.DrawFocus メソッド

メモ : このメソッドは、.NET Framework version 2.0新しく追加されたものです。

指定した境界周囲フォーカスを表す四角形描画ます。

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

Public Sub DrawFocus ( _
    bounds As Rectangle, _
    cellsPaintSelectionBackground As Boolean
 _
)
Dim instance As DataGridViewRowPostPaintEventArgs
Dim bounds As Rectangle
Dim cellsPaintSelectionBackground As Boolean

instance.DrawFocus(bounds, cellsPaintSelectionBackground)
public void DrawFocus (
    Rectangle bounds,
    bool cellsPaintSelectionBackground
)
public:
void DrawFocus (
    Rectangle bounds, 
    bool cellsPaintSelectionBackground
)
public void DrawFocus (
    Rectangle bounds, 
    boolean cellsPaintSelectionBackground
)
public function DrawFocus (
    bounds : Rectangle, 
    cellsPaintSelectionBackground : boolean
)

パラメータ

bounds

フォーカス領域指定する Rectangle

cellsPaintSelectionBackground

DataGridViewRow.InheritedStyle プロパティの SelectionBackColor プロパティ使用してフォーカスを表す四角形の色を決定する場合trueDataGridViewRow.InheritedStyle プロパティBackColor プロパティ使用する場合false

例外例外
例外種類条件

InvalidOperationException

RowIndex が 0 未満か、DataGridView コントロール行数から 1 を引いた値を上回ってます。

解説解説

DataGridViewRow およびそのセル内容自分描画する場合は、DrawFocus メソッド使用します

使用例使用例

DrawFocus メソッド使用して、行に表示されているセル周囲フォーカス描画する方法次のコード例示します次の例は「方法 : Windows フォームの DataGridView コントロールの行の外観カスタマイズする」で取り上げている例の一部です。

' Paints the content that spans multiple columns and the focus rectangle.
Sub dataGridView1_RowPostPaint(ByVal sender
 As Object, _
    ByVal e As DataGridViewRowPostPaintEventArgs)
 _
    Handles dataGridView1.RowPostPaint

    ' Calculate the bounds of the row.
    Dim rowBounds As New
 Rectangle(Me.dataGridView1.RowHeadersWidth, _
        e.RowBounds.Top, Me.dataGridView1.Columns.GetColumnsWidth(
 _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, e.RowBounds.Height)

    Dim forebrush As SolidBrush = Nothing
    Try
        ' Determine the foreground color.
        If (e.State And DataGridViewElementStates.Selected)
 = _
            DataGridViewElementStates.Selected Then

            forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
        Else
            forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
        End If

        ' Get the content that spans multiple columns.
        Dim recipe As Object
 = _
            Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value

        If Not (recipe Is
 Nothing) Then
            Dim text As String
 = recipe.ToString()

            ' Calculate the bounds for the content that spans multiple
 
            ' columns, adjusting for the horizontal scrolling position
 
            ' and the current row height, and displaying only whole
            ' lines of text.
            Dim textArea As Rectangle = rowBounds
            textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
            textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height)
 * _
                e.InheritedRowStyle.Font.Height

            ' Calculate the portion of the text area that needs painting.
            Dim clip As RectangleF = textArea
            clip.Width -= Me.dataGridView1.RowHeadersWidth + 1
 - clip.X
            clip.X = Me.dataGridView1.RowHeadersWidth + 1
            Dim oldClip As RectangleF = e.Graphics.ClipBounds
            e.Graphics.SetClip(clip)

            ' Draw the content that spans multiple columns.
            e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                textArea)

            e.Graphics.SetClip(oldClip)
        End If
    Finally
        forebrush.Dispose()
    End Try

    If Me.dataGridView1.CurrentCellAddress.Y
 = e.RowIndex Then
        ' Paint the focus rectangle.
        e.DrawFocus(rowBounds, True)
    End If

End Sub 'dataGridView1_RowPostPaint
// Paints the content that spans multiple columns and the focus rectangle.
void dataGridView1_RowPostPaint(object sender,
    DataGridViewRowPostPaintEventArgs e)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    SolidBrush forebrush = null;
    try
    {
        // Determine the foreground color.
        if ((e.State & DataGridViewElementStates.Selected)
 ==
            DataGridViewElementStates.Selected)
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
        }
        else
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
        }

        // Get the content that spans multiple columns.
        object recipe =
            this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value;

        if (recipe != null)
        {
            String text = recipe.ToString();

            // Calculate the bounds for the content that spans multiple
 
            // columns, adjusting for the horizontal scrolling position
 
            // and the current row height, and displaying only whole
            // lines of text.
            Rectangle textArea = rowBounds;
            textArea.X -= this.dataGridView1.HorizontalScrollingOffset;
            textArea.Width += this.dataGridView1.HorizontalScrollingOffset;
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom;
            textArea.Height -= rowBounds.Height -
                e.InheritedRowStyle.Padding.Bottom;
            textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height)
 *
                e.InheritedRowStyle.Font.Height;

            // Calculate the portion of the text area that needs painting.
            RectangleF clip = textArea;
            clip.Width -= this.dataGridView1.RowHeadersWidth +
 1 - clip.X;
            clip.X = this.dataGridView1.RowHeadersWidth + 1;
            RectangleF oldClip = e.Graphics.ClipBounds;
            e.Graphics.SetClip(clip);

            // Draw the content that spans multiple columns.
            e.Graphics.DrawString(
                text, e.InheritedRowStyle.Font, forebrush, textArea);

            e.Graphics.SetClip(oldClip);
        }
    }
    finally
    {
        forebrush.Dispose();
    }

    if (this.dataGridView1.CurrentCellAddress.Y
 == e.RowIndex)
    {
        // Paint the focus rectangle.
        e.DrawFocus(rowBounds, true);
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewRowPostPaintEventArgs クラス
DataGridViewRowPostPaintEventArgs メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridViewCellStyle.BackColor プロパティ
DataGridViewCellStyle.SelectionBackColor プロパティ
DataGridViewRow クラス



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

辞書ショートカット

すべての辞書の索引

「DataGridViewRowPostPaintEventArgs.DrawFocus メソッド」の関連用語

DataGridViewRowPostPaintEventArgs.DrawFocus メソッドのお隣キーワード
検索ランキング

   

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



DataGridViewRowPostPaintEventArgs.DrawFocus メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS