您的位置:首页 > 其它

DataGridView鼠标经过Cell时弹出对话框

2013-05-16 09:14 169 查看
Private Sub gdv_view_schedule_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles gdv_view_schedule.MouseMove

Dim hitCell As DataGridView.HitTestInfo = Me.gdv_view_schedule.HitTest(e.X, e.Y)

Dim screenPoint As Point = Me.gdv_view_schedule.PointToScreen(New Point(e.X, e.Y))

Dim row_index As Integer = hitCell.RowIndex

Dim column_index As Integer = hitCell.ColumnIndex

If row_index = -1 OrElse column_index = -1 Then

Return

End If

Dim cell As DataGridViewCell = Me.gdv_view_schedule.Rows(row_index).Cells(column_index)

Dim frist_cell, last_cell, next_cell As DataGridViewCell

Dim start_time, end_time As DateTime

If Not cell.Value Is Convert.DBNull Then

If cell.Value = "Overlap" Then

frist_cell = Me.gdv_view_schedule.Rows(row_index).Cells(0)

last_cell = Me.gdv_view_schedule.Rows(row_index - 1).Cells(column_index)

next_cell = Me.gdv_view_schedule.Rows(row_index + 1).Cells(column_index)

For i As Integer = 0 To Me.end_time.Count - 1

If CType(Me.end_time(i), DateTime).Hour = CType(frist_cell.Value, DateTime).Hour Then

end_time = CType(Me.end_time(i), DateTime)

start_time = CType(Me.start_time(i), DateTime)

End If

Next

If Me.currentCell Is cell Then

Return

End If

If Not Me.currentCell Is cell Then

If (Not Me.hourScheduleViewForm Is Nothing) Then

Me.hourScheduleViewForm.Close()

End If

End If

Me.hourScheduleViewForm = New HourScheduleViewForm()

AddHandler hourScheduleViewForm.ViewFormClosed, AddressOf Me.ViewFormClosed

Me.hourScheduleViewForm.Init(Me.addOnModule, end_time, start_time, last_cell.ToolTipText, cell.ToolTipText, last_cell.Style.BackColor, next_cell.Style.BackColor)

Me.hourScheduleViewForm.Location = screenPoint

Me.hourScheduleViewForm.Show()

'Me.Focus()

Me.currentCell = cell

Else

If (Not Me.hourScheduleViewForm Is Nothing) Then

Me.hourScheduleViewForm.Close()

End If

Me.currentCell = cell

End If

End If

End Sub

备注:HourScheduleViewForm这个窗体使用SplashScreen(初始屏幕)效果会好些,类似于tooltip的效果;同时 Me.hourScheduleViewForm public 变量,主要是为确保每次仅只弹出一个窗体;其中有一部分是用于个人系统的判断代码,不需要时可以直接删除,防止代码冗余

原文:http://blog.csdn.com/wangpeixian/article/details/4348265
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: