newyuppie
asked on
MDI CLIENT AREA MOUSE WHEEL SCROLL
hi experts,
in vb 2005, i have a parent main form and a child form that occupies more than the client area's height so i need to scroll down to see it fully. i would like to be able to detect mouse wheel event so that i can scroll the mdi client area down as if i were scrolling it manually with the scrollbar.
i couldnt find any piece of info on the net about this...
thanks
in vb 2005, i have a parent main form and a child form that occupies more than the client area's height so i need to scroll down to see it fully. i would like to be able to detect mouse wheel event so that i can scroll the mdi client area down as if i were scrolling it manually with the scrollbar.
i couldnt find any piece of info on the net about this...
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1) Visually slow? Built-in code? Haven't found it yet.
2) If you use the scroll bars from the MDI parent, how does look when scrolling?
3) I only figured out yesterday what MDI forms are actually doing to scroll child forms.
Bob
2) If you use the scroll bars from the MDI parent, how does look when scrolling?
3) I only figured out yesterday what MDI forms are actually doing to scroll child forms.
Bob
ASKER
good to know im not the only one up in the middle of the night...
thanks for your example code, i just adapted it a little bit and it is working fine. in case anyone needs something similar, here's my messy code (sorry, virtually not commented, but as there is currently no info on this anywhere on the net it may serve you as well). Please if anybody designs a better approach post it in this question so we can have a source of reference for this issue.
Private Structure scrollInfo
Private _direction As Integer
''' <summary>
''' Gets scrolling direction
''' </summary>
''' <value>Scrolling direction</value>
''' <returns>Direction of scroll "UP" or "DOWN"</returns>
Friend ReadOnly Property Direction() As String
Get
If _direction < 0 Then
Return "DOWN"
Else
Return "UP"
End If
End Get
End Property
''' <summary>
''' Sets scrolling direction
''' </summary>
''' <value>Scrolling direction</value>
Friend WriteOnly Property SetDirection() As Integer
Set(ByVal value As Integer)
_direction = value
End Set
End Property
End Structure
Private Sub FormMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) Handles Me.MouseWheel
'scrolling factor
Dim ScrFactor As Integer = 80
Dim frm As Form
Dim scrollInfo As scrollInfo
Dim _Has2ScrollDown As Boolean = False
Dim _Has2ScrollUp As Boolean = False
scrollInfo.SetDirection = Math.Sign(e.Delta)
For Each frm In Me.MdiChildren
If Not _Has2ScrollUp Then
_Has2ScrollUp = frm.Top < 0
End If
If Not _Has2ScrollDown Then
_Has2ScrollDown = Me.ScrollToControl(frm).Y < 0
End If
Next
For Each frm In Me.MdiChildren
If scrollInfo.Direction = "UP" Then
If _Has2ScrollUp Then
frm.Top += Math.Sign(e.Delta) * ScrFactor
End If
ElseIf scrollInfo.Direction = "DOWN" Then
If _Has2ScrollDown Then
frm.Top += Math.Sign(e.Delta) * ScrFactor
End If
End If
Next
'Me.Refresh()
End Sub
thanks for your example code, i just adapted it a little bit and it is working fine. in case anyone needs something similar, here's my messy code (sorry, virtually not commented, but as there is currently no info on this anywhere on the net it may serve you as well). Please if anybody designs a better approach post it in this question so we can have a source of reference for this issue.
Private Structure scrollInfo
Private _direction As Integer
''' <summary>
''' Gets scrolling direction
''' </summary>
''' <value>Scrolling direction</value>
''' <returns>Direction of scroll "UP" or "DOWN"</returns>
Friend ReadOnly Property Direction() As String
Get
If _direction < 0 Then
Return "DOWN"
Else
Return "UP"
End If
End Get
End Property
''' <summary>
''' Sets scrolling direction
''' </summary>
''' <value>Scrolling direction</value>
Friend WriteOnly Property SetDirection() As Integer
Set(ByVal value As Integer)
_direction = value
End Set
End Property
End Structure
Private Sub FormMain_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.Mouse
'scrolling factor
Dim ScrFactor As Integer = 80
Dim frm As Form
Dim scrollInfo As scrollInfo
Dim _Has2ScrollDown As Boolean = False
Dim _Has2ScrollUp As Boolean = False
scrollInfo.SetDirection = Math.Sign(e.Delta)
For Each frm In Me.MdiChildren
If Not _Has2ScrollUp Then
_Has2ScrollUp = frm.Top < 0
End If
If Not _Has2ScrollDown Then
_Has2ScrollDown = Me.ScrollToControl(frm).Y < 0
End If
Next
For Each frm In Me.MdiChildren
If scrollInfo.Direction = "UP" Then
If _Has2ScrollUp Then
frm.Top += Math.Sign(e.Delta) * ScrFactor
End If
ElseIf scrollInfo.Direction = "DOWN" Then
If _Has2ScrollDown Then
frm.Top += Math.Sign(e.Delta) * ScrFactor
End If
End If
Next
'Me.Refresh()
End Sub
ASKER
i have some comments on this answer:
1) it works fine, but it can be a little visually slow. isn't there any built in code that would be faster?
2) the forms look like they jump up and down with the wheel. how could i implement a smooth scroll using your approach?
thank you!