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

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

DataGridViewCellPaintingEventArgs.CellStyle プロパティ

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

現在の DataGridViewCell のセル スタイル取得します

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

Public ReadOnly Property
 CellStyle As DataGridViewCellStyle
Dim instance As DataGridViewCellPaintingEventArgs
Dim value As DataGridViewCellStyle

value = instance.CellStyle
public DataGridViewCellStyle CellStyle { get;
 }
public:
property DataGridViewCellStyle^ CellStyle {
    DataGridViewCellStyle^ get ();
}
/** @property */
public DataGridViewCellStyle get_CellStyle ()
public function get CellStyle
 () : DataGridViewCellStyle

プロパティ
現在の DataGridViewCellセル スタイル格納された DataGridViewCellStyle。

解説解説

CellStyle プロパティの各プロパティ設定することにより、現在の DataGridViewCell外観変更します

使用例使用例

このメンバ使用方法次のコード例示します

Private Sub dataGridView1_CellPainting(ByVal
 sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)
 _
    Handles dataGridView1.CellPainting

    If Me.dataGridView1.Columns("ContactName").Index
 = _
        e.ColumnIndex AndAlso e.RowIndex >= 0 Then

        Dim newRect As New
 Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
            e.CellBounds.Width - 4, e.CellBounds.Height - 4)
        Dim backColorBrush As New
 SolidBrush(e.CellStyle.BackColor)
        Dim gridBrush As New
 SolidBrush(Me.dataGridView1.GridColor)
        Dim gridLinePen As New
 Pen(gridBrush)

        Try

            ' Erase the cell.
            e.Graphics.FillRectangle(backColorBrush, e.CellBounds)

            ' Draw the grid lines (only the right and bottom lines;
            ' DataGridView takes care of the others).
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
                e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom - 1)
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
                e.CellBounds.Top, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom)

            ' Draw the inset highlight box.
            e.Graphics.DrawRectangle(Pens.Blue, newRect)

            ' Draw the text content of the cell, ignoring alignment.
            If Not (e.Value Is
 Nothing) Then
                e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
                Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
                StringFormat.GenericDefault)
            End If
            e.Handled = True

        Finally
            gridLinePen.Dispose()
            gridBrush.Dispose()
            backColorBrush.Dispose()
        End Try

    End If

End Sub
private void dataGridView1_CellPainting(object
 sender,
System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
    if (this.dataGridView1.Columns["ContactName"].Index
 ==
        e.ColumnIndex && e.RowIndex >= 0)
    {
        Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
            e.CellBounds.Y + 1, e.CellBounds.Width - 4,
            e.CellBounds.Height - 4);

        using (
            Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor)
,
            backColorBrush = new SolidBrush(e.CellStyle.BackColor))
        {
            using (Pen gridLinePen = new Pen(gridBrush))
            {
                // Erase the cell.
                e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

                // Draw the grid lines (only the right and bottom lines;
                // DataGridView takes care of the others).
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                    e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom - 1);
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                    e.CellBounds.Top, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom);

                // Draw the inset highlight box.
                e.Graphics.DrawRectangle(Pens.Blue, newRect);

                // Draw the text content of the cell, ignoring alignment.
                if (e.Value != null)
                {
                    e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                        Brushes.Crimson, e.CellBounds.X + 2,
                        e.CellBounds.Y + 2, StringFormat.GenericDefault);
                }
                e.Handled = true;
            }
        }
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewCellPaintingEventArgs クラス
DataGridViewCellPaintingEventArgs メンバ
System.Windows.Forms 名前空間
DataGridView クラス
DataGridViewCell クラス
DataGridViewCellStyle


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

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

辞書ショートカット

すべての辞書の索引

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

   

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



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

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

©2025 GRAS Group, Inc.RSS