Event on Scrolling to the end in flowlayoutpanel
-
Is there a way that I can fire an event when the user scrolls to the end of the flowlayoutpanel? if so then can you please tell how to do it? just a quick note: I am using the autoscroll/horizontal scrollbar. Algorithm: If scroll.value = endofthispage then msgbox("You are at the end of this page") else 'do nothing end if
-
Is there a way that I can fire an event when the user scrolls to the end of the flowlayoutpanel? if so then can you please tell how to do it? just a quick note: I am using the autoscroll/horizontal scrollbar. Algorithm: If scroll.value = endofthispage then msgbox("You are at the end of this page") else 'do nothing end if
-
So I tried to do something like that today.
If e.NewValue = e.OldValue Then MsgBox("hi") End If
but it is not working the way I want it to work... The problem is that now if I click the arrows on the scroll bar, then only it works, if I use the (bar) *not the left/top right/bottom arrows, it shows the message box like 100x times. but even then I am having a problem. the problem is that, when I scroll back to the beginning, it shows that message box again.
-
So I tried to do something like that today.
If e.NewValue = e.OldValue Then MsgBox("hi") End If
but it is not working the way I want it to work... The problem is that now if I click the arrows on the scroll bar, then only it works, if I use the (bar) *not the left/top right/bottom arrows, it shows the message box like 100x times. but even then I am having a problem. the problem is that, when I scroll back to the beginning, it shows that message box again.
Perhaps its not as MS once intended it. or perhaps it is...but the scrolling and value changed are two differed events. if you press one of the scrolls arrows the program will make it scroll in that direction once. and then change the value. but when you drag the bar you scroll every time you move a little...but the value is only changed upon the key release. a easy thing to do is to declare a private boolean (outside the event). and switch it true/false so the message box only displays once.
Private ScrollingMessage as Boolean = true 'I know not the right place to declare it... put it with your other declarations
'put this below into your event
If e.NewValue = e.OldValue and ScrollingMessage Then
MsgBox("hi")
ScrollingMessage = false
elseif e.NewValue <> e.OldValue then
scrollingmessage = true
End If -
Perhaps its not as MS once intended it. or perhaps it is...but the scrolling and value changed are two differed events. if you press one of the scrolls arrows the program will make it scroll in that direction once. and then change the value. but when you drag the bar you scroll every time you move a little...but the value is only changed upon the key release. a easy thing to do is to declare a private boolean (outside the event). and switch it true/false so the message box only displays once.
Private ScrollingMessage as Boolean = true 'I know not the right place to declare it... put it with your other declarations
'put this below into your event
If e.NewValue = e.OldValue and ScrollingMessage Then
MsgBox("hi")
ScrollingMessage = false
elseif e.NewValue <> e.OldValue then
scrollingmessage = true
End Ifyeah but this still causes the issue of 100x message boxes that are displayed when I use the bar instead of the arrows. Edit: And the issue of back scroll is still there..
-
yeah but this still causes the issue of 100x message boxes that are displayed when I use the bar instead of the arrows. Edit: And the issue of back scroll is still there..
Oke started a little project to test a bit around and i think you might find this interesting. i used a form called form1. and placed a listbox on it i called txtscroll. I suggest you make a same sort of window and paste the following code in to see how it works:
Public Class Form1
Dim WithEvents scrollhandler As MyListener 'class that will watch windows to see if your scrolling Private scrolled As Boolean = False 'boolean you can use to flip if a message box was displayed or not...(so it wont loop the messagebox.show) Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'some random loop i used to ditch some data in my listbox for testing Dim index As Int32 = 0 Do While index < 100 txtscroll.Items.Add(index.ToString()) index += 1 Loop 'attach your scrollwatcher to your control. in my case i have a listbox called "txtscroll") scrollhandler = New MyListener(txtscroll) End Sub Private Sub scrollhandler\_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles scrollhandler.MyScroll 'place your if/else statement here, its smart to use the scrolled boolean to flip true/false so the messagebox doesnt go on a loop End Sub Private Sub txtscroll\_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtscroll.MouseWheel scrollhandler\_MyScroll(e, e) 'needed to catch the scrollwheel event. End Sub Private Class MyListener Inherits NativeWindow Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs) Const WM\_MOUSEACTIVATE = &H21 Const WM\_MOUSEMOVE = &H200 Private control As Control Public Sub New(ByVal control As Control) AssignHandle(control.Handle) 'docks handler to given control End Sub Protected Overrides Sub WndProc(ByRef Messageevent As Message) Const WM\_HSCROLL = &H114 Const WM\_VSCROLL = &H115 If Messageevent.Msg = WM\_HSCROLL Or Messageevent.Msg = WM\_VSCROLL Then 'looks if the horisontal or verticle scrollbar is moving 'one of the scrollbars is moving, throw event RaiseEvent MyScroll(control, New EventArgs) End If MyBase.WndProc(Messageevent) End Sub Protected Overrides Sub Finalize() 'not used in example but drops the
-
Is there a way that I can fire an event when the user scrolls to the end of the flowlayoutpanel? if so then can you please tell how to do it? just a quick note: I am using the autoscroll/horizontal scrollbar. Algorithm: If scroll.value = endofthispage then msgbox("You are at the end of this page") else 'do nothing end if
private int previousValue;
public void someEventHandler(...) {
int currentValue=...;
if (currentValue==extremeValue && currentValue!=previousValue) doWhatEver();
previousValue=currentValue;
}:)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
private int previousValue;
public void someEventHandler(...) {
int currentValue=...;
if (currentValue==extremeValue && currentValue!=previousValue) doWhatEver();
previousValue=currentValue;
}:)
Luc Pattyn [My Articles] Nil Volentibus Arduum
oeh quite nice! might actually try that in the future. but isn't that C#?
-
oeh quite nice! might actually try that in the future. but isn't that C#?
I'd call it pseudo-code around here :-D
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
I'd call it pseudo-code around here :-D
Luc Pattyn [My Articles] Nil Volentibus Arduum
1-0 for you ;)
-
Oke started a little project to test a bit around and i think you might find this interesting. i used a form called form1. and placed a listbox on it i called txtscroll. I suggest you make a same sort of window and paste the following code in to see how it works:
Public Class Form1
Dim WithEvents scrollhandler As MyListener 'class that will watch windows to see if your scrolling Private scrolled As Boolean = False 'boolean you can use to flip if a message box was displayed or not...(so it wont loop the messagebox.show) Private Sub Form1\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'some random loop i used to ditch some data in my listbox for testing Dim index As Int32 = 0 Do While index < 100 txtscroll.Items.Add(index.ToString()) index += 1 Loop 'attach your scrollwatcher to your control. in my case i have a listbox called "txtscroll") scrollhandler = New MyListener(txtscroll) End Sub Private Sub scrollhandler\_MyScroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles scrollhandler.MyScroll 'place your if/else statement here, its smart to use the scrolled boolean to flip true/false so the messagebox doesnt go on a loop End Sub Private Sub txtscroll\_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtscroll.MouseWheel scrollhandler\_MyScroll(e, e) 'needed to catch the scrollwheel event. End Sub Private Class MyListener Inherits NativeWindow Public Event MyScroll(ByVal sender As Object, ByVal e As EventArgs) Const WM\_MOUSEACTIVATE = &H21 Const WM\_MOUSEMOVE = &H200 Private control As Control Public Sub New(ByVal control As Control) AssignHandle(control.Handle) 'docks handler to given control End Sub Protected Overrides Sub WndProc(ByRef Messageevent As Message) Const WM\_HSCROLL = &H114 Const WM\_VSCROLL = &H115 If Messageevent.Msg = WM\_HSCROLL Or Messageevent.Msg = WM\_VSCROLL Then 'looks if the horisontal or verticle scrollbar is moving 'one of the scrollbars is moving, throw event RaiseEvent MyScroll(control, New EventArgs) End If MyBase.WndProc(Messageevent) End Sub Protected Overrides Sub Finalize() 'not used in example but drops the
Thanks for the example. but I still can't figure out how I can use this to know if the user has scrolled to the end.
-
private int previousValue;
public void someEventHandler(...) {
int currentValue=...;
if (currentValue==extremeValue && currentValue!=previousValue) doWhatEver();
previousValue=currentValue;
}:)
Luc Pattyn [My Articles] Nil Volentibus Arduum
isn't previousValue a readonly value?
-
isn't previousValue a readonly value?
did I declare it read-only? :confused:
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
did I declare it read-only? :confused:
Luc Pattyn [My Articles] Nil Volentibus Arduum
Seems like I misunderstood the algorithm.
-
Thanks for the example. but I still can't figure out how I can use this to know if the user has scrolled to the end.
hmm, oke im not really sure why you want to show that messagebox. but I thrown in some more trail and error and i came up with the code below. Note that I ran a little low on time so its a bit of a mess...i recommend throwing in a breakpoint to figure out exactly how the code works before putting it into your project. to test it again make a form (called form1) and add a listbox (txtscroll) in it. then copy paste the code into your form.
Imports System.Runtime.InteropServices
Public Class Form1
Dim WithEvents scrollhandler As MyListener 'class that will watch windows to see if your scrolling
Private scrolled As Boolean = False 'boolean you can use to flip if a message box was displayed or not...(so it wont loop the messagebox.show)
Private maxscroll As Int64 'int used to store the max value of the scrollbar
'dll used to get the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash!
_
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function'dll used to set the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash! \_ Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer End Function Private Const SB\_HORZ As Integer = &H0 Private Const SB\_VERT As Integer = &H1 Public Property HScrollPos() As Integer 'property to set or get the horisontal scrollbar value Get Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ) 'change txtscroll to the control you use. dont forget the .handle End Get Set(ByVal value As Integer) SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ, value, True) 'change txtscroll to the control you use. dont forget the .handle End Set End Property Public Property VScrollPos() As Integer 'Property to set or get the Vertical scrollbar value Get Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_VERT) 'change txtscroll to the control you use. dont forget the .handle End Get Set(ByVal value As Integer) SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_VERT, value, True) 'change txtscroll to the control you use. dont forget the .handle End Set
-
hmm, oke im not really sure why you want to show that messagebox. but I thrown in some more trail and error and i came up with the code below. Note that I ran a little low on time so its a bit of a mess...i recommend throwing in a breakpoint to figure out exactly how the code works before putting it into your project. to test it again make a form (called form1) and add a listbox (txtscroll) in it. then copy paste the code into your form.
Imports System.Runtime.InteropServices
Public Class Form1
Dim WithEvents scrollhandler As MyListener 'class that will watch windows to see if your scrolling
Private scrolled As Boolean = False 'boolean you can use to flip if a message box was displayed or not...(so it wont loop the messagebox.show)
Private maxscroll As Int64 'int used to store the max value of the scrollbar
'dll used to get the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash!
_
Public Shared Function GetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer) As Integer
End Function'dll used to set the scrollbar value NOTE: if the scrollbar is not visible or you go higher then your max it will crash! \_ Private Shared Function SetScrollPos(ByVal hWnd As IntPtr, ByVal nBar As Integer, ByVal nPos As Integer, ByVal bRedraw As Boolean) As Integer End Function Private Const SB\_HORZ As Integer = &H0 Private Const SB\_VERT As Integer = &H1 Public Property HScrollPos() As Integer 'property to set or get the horisontal scrollbar value Get Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ) 'change txtscroll to the control you use. dont forget the .handle End Get Set(ByVal value As Integer) SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_HORZ, value, True) 'change txtscroll to the control you use. dont forget the .handle End Set End Property Public Property VScrollPos() As Integer 'Property to set or get the Vertical scrollbar value Get Return GetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_VERT) 'change txtscroll to the control you use. dont forget the .handle End Get Set(ByVal value As Integer) SetScrollPos(DirectCast(txtscroll.Handle, IntPtr), SB\_VERT, value, True) 'change txtscroll to the control you use. dont forget the .handle End Set
Did you test the code...? Well... Because the above didn't work for me. I made a test project to see how it works. but it didn't show me any message...
-
Did you test the code...? Well... Because the above didn't work for me. I made a test project to see how it works. but it didn't show me any message...
Did you recalculate the max value of your scrollbar? if your listbox is of a differed size then mine (witch it probably is) you have to recalculate it. just run the program. dont scroll and see how many items fit into the listbox (for me that where 18). you want to do the index - [the number you found]. after that it should work.
maxscroll = index - 18 'calculate max value. everytime you add a item you have to do this again. to calculate this its a bit of a trail and error thing depending on your control
-
Did you recalculate the max value of your scrollbar? if your listbox is of a differed size then mine (witch it probably is) you have to recalculate it. just run the program. dont scroll and see how many items fit into the listbox (for me that where 18). you want to do the index - [the number you found]. after that it should work.
maxscroll = index - 18 'calculate max value. everytime you add a item you have to do this again. to calculate this its a bit of a trail and error thing depending on your control
Oh that kinda worked... but how am I ganna calculate the value in a control like this one: When its normal screen size: http://foto.pk/images/minx.png[^] When its maximized: http://foto.pk/images/maxx.png[^] ------------------------------------------------------------- Btw. You asked why would I want to know this value before... Answer) I don't actually want to show users "yay u reached the bottom" lol. I want the program to get more tweets when it reaches there. The above that I am making is a v2 of my current twitter client called TRocket. TRocket - Twitter Client [Open Source][^]
-
Oh that kinda worked... but how am I ganna calculate the value in a control like this one: When its normal screen size: http://foto.pk/images/minx.png[^] When its maximized: http://foto.pk/images/maxx.png[^] ------------------------------------------------------------- Btw. You asked why would I want to know this value before... Answer) I don't actually want to show users "yay u reached the bottom" lol. I want the program to get more tweets when it reaches there. The above that I am making is a v2 of my current twitter client called TRocket. TRocket - Twitter Client [Open Source][^]
How do you fill the listbox? with a loop or a data binding? EDIT: oke something just shot to my mind. the items you add to your listbox are controls right? i forgot the object name but i've seen the code of those. this means they have a fixed sized right? you could calculate how much fit into your listbox if you read out the length and hight of it. lets say for example your listbox is 300 pixels wide and 400 pixels high. your controls are 100 wide and 50 high. this would mean you can fit 3 rows of each 8 items = 24 items without scroll bar. so in a 'math' way:
[ammount of items] - (math.floor([with_listbox]/[with_control])+math.floor([hight_listbox]/[hight_control])) = maximum scroll value
------------------- Ah oke, yea now its making sense ;) and i already figured it was for Trocket (read the thread about it) when i was helping you with a previous question.
-
How do you fill the listbox? with a loop or a data binding? EDIT: oke something just shot to my mind. the items you add to your listbox are controls right? i forgot the object name but i've seen the code of those. this means they have a fixed sized right? you could calculate how much fit into your listbox if you read out the length and hight of it. lets say for example your listbox is 300 pixels wide and 400 pixels high. your controls are 100 wide and 50 high. this would mean you can fit 3 rows of each 8 items = 24 items without scroll bar. so in a 'math' way:
[ammount of items] - (math.floor([with_listbox]/[with_control])+math.floor([hight_listbox]/[hight_control])) = maximum scroll value
------------------- Ah oke, yea now its making sense ;) and i already figured it was for Trocket (read the thread about it) when i was helping you with a previous question.
huh? Sorry but I didn't quiet get that... wasn't quiet good in maths :/ Can you check into the source code: http://www.mediafire.com/?m13i05h0vmb11yc[^] I actually want this to be on Flowlayoutpanel1.