2013年4月17日水曜日

Vb DataGridView フォーカスを示す四角形点線枠を消す方法

Vb DataGridView フォーカスを示す四角形点線枠を消す方法
1. CellPaintingイベントハンドラで自分で枠を描くように
  'CellPaintingイベントハンドラ
Private Sub DataGridView1_CellPainting(ByVal sender As Object, _
        ByVal e As DataGridViewCellPaintingEventArgs) _
        Handles DataGridView1.CellPainting
    'ヘッダー以外のとき
    If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
        'フォーカス枠以外が描画されるようにする
        Dim paintParts As DataGridViewPaintParts = _
            e.PaintParts And Not DataGridViewPaintParts.Focus
        'セルを描画する
        e.Paint(e.ClipBounds, paintParts)

        '描画が完了したことを知らせる
        e.Handled = True
    End If
End Sub
参考URL

2.DataGridViewのShowFocusCuesをオーバーライドし、常にfalseを返すように
public class DatagridViewGS : DatagridView
 {
   protected override bool ShowFocusCues
   {
     get { return false; }
   }
 }

0 件のコメント:

コメントを投稿