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
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
该博客介绍了如何在Windows Forms应用程序中,当鼠标移动到DataGridView单元格上时,弹出一个对话框展示详细信息。通过HitTest方法获取单元格位置,并在特定条件下显示HourScheduleViewForm窗体,模拟Tooltip效果。代码中还包括了窗体关闭和位置设置的逻辑,以及防止多个窗体弹出的处理。 HourScheduleViewForm的初始化参数包括开始时间、结束时间等,提供了一种增强的用户交互体验。
8104

被折叠的 条评论
为什么被折叠?



