-
Sep 18th, 2014, 04:22 AM
#1
_Scroll not being called??
Ok... I have a control with AutoScroll and want a way to work out when the control area has been scrolled regardless of how it was scrolled ...
Q1: How is it best to do this?
The reason I ask is that the _Scroll event doesn't get fired when the control is scrolled by using the scroll wheel ... so I have to use this as well ... and now I have just realised that when a sub-control gets focus .Net automatically scrolls the control into view (which is fine) ... but the event is not called ...
Q2: What event will pickup the focus situation discussed above?
Thanks,
Kris
-
Sep 18th, 2014, 12:10 PM
#2
Re: _Scroll not being called??
Maybe inherit the control and RaiseEvent for ScrollToControl?
Code:
Public Class FLPanelEx
Inherits FlowLayoutPanel
Public Event ScrollingToControl()
Protected Overrides Function ScrollToControl(activeControl As System.Windows.Forms.Control) As System.Drawing.Point
RaiseEvent ScrollingToControl()
Return MyBase.ScrollToControl(activeControl)
End Function
End Class
Test,
Code:
Public Class Form1
Private Sub FlPanelEx1_MouseEnter(sender As Object, e As System.EventArgs) Handles FlPanelEx1.MouseEnter
FlPanelEx1.Select() ' so we can use mouse wheel
End Sub
Private Sub FlPanelEx1_MouseWheel(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles FlPanelEx1.MouseWheel
Debug.WriteLine("MouseWheel")
End Sub
Private Sub FlPanelEx1_Scroll(sender As Object, e As System.Windows.Forms.ScrollEventArgs) Handles FlPanelEx1.Scroll
Debug.WriteLine("Scroll")
End Sub
Private Sub FlPanelEx1_ScrollingToControl() Handles FlPanelEx1.ScrollingToControl
Debug.WriteLine("Scrolling to a control")
End Sub
End Class
-
Sep 18th, 2014, 04:55 PM
#3
Re: _Scroll not being called??
Similar to Edgmeal's solution but also handling the MouseWheel and firing the Scroll event instead of a custom one.
Code:
Public Class SC
Inherits ScrollableControl
Protected Overrides Function ScrollToControl(activeControl As System.Windows.Forms.Control) As System.Drawing.Point
Dim current As Point = New Point(-Me.DisplayRectangle.Location.X, -Me.DisplayRectangle.Location.Y)
Dim newPos As Point = MyBase.ScrollToControl(activeControl)
FireNewScroll(current, New Point(-newPos.X, -newPos.Y))
Return newPos
End Function
Protected Overrides Sub OnMouseWheel(e As System.Windows.Forms.MouseEventArgs)
Dim current As Point = New Point(Me.HorizontalScroll.Value, Me.VerticalScroll.Value)
MyBase.OnMouseWheel(e)
Dim newPos As Point = New Point(Me.HorizontalScroll.Value, Me.VerticalScroll.Value)
FireNewScroll(current, newPos)
End Sub
Private Sub FireNewScroll(oldpos As Point, newpos As Point)
If oldpos.X <> newpos.X Then
Me.OnScroll(New ScrollEventArgs(ScrollEventType.EndScroll, oldpos.X, newpos.X, ScrollOrientation.HorizontalScroll))
End If
If oldpos.Y <> newpos.Y Then
Me.OnScroll(New ScrollEventArgs(ScrollEventType.EndScroll, oldpos.Y, newpos.Y, ScrollOrientation.VerticalScroll))
End If
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|