Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Event on Scrolling to the end in flowlayoutpanel

Event on Scrolling to the end in flowlayoutpanel

Scheduled Pinned Locked Moved Visual Basic
algorithmstutorialquestion
27 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Ammar_Ahmad

    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.

    N Offline
    N Offline
    Nick Otten
    wrote on last edited by
    #21

    Private Function CalculateMaxScrollValue(ByVal totalitems As Int64, ByVal controlhight As Int32, ByVal controlwith As Int32)
    'NOTE: 482 and 114 is the size property of your msgctrl.vb
    Return totalitems - (Math.Floor(controlwith / 482) * Math.Floor(controlhight / 114))
    End Function

    Add that function to your code to find the max scroll value. Use that in combination with the code i send you in the previous posts in this topic. replace the txtscroll with the flowlayoutpanel1 and it should work (cant test it here). as a side note: you might want to fine tune the if/else of mine a little to a "<" instead of "=". giving a exact value to a 'analog' control gives it a small change to trigger. also it seems like the program is single threaded. i don't know how long it takes to load those messages but your interface will hang (not responding ect) till the load is complete. looking into threading might be interesting.

    A 1 Reply Last reply
    0
    • N Nick Otten

      Private Function CalculateMaxScrollValue(ByVal totalitems As Int64, ByVal controlhight As Int32, ByVal controlwith As Int32)
      'NOTE: 482 and 114 is the size property of your msgctrl.vb
      Return totalitems - (Math.Floor(controlwith / 482) * Math.Floor(controlhight / 114))
      End Function

      Add that function to your code to find the max scroll value. Use that in combination with the code i send you in the previous posts in this topic. replace the txtscroll with the flowlayoutpanel1 and it should work (cant test it here). as a side note: you might want to fine tune the if/else of mine a little to a "<" instead of "=". giving a exact value to a 'analog' control gives it a small change to trigger. also it seems like the program is single threaded. i don't know how long it takes to load those messages but your interface will hang (not responding ect) till the load is complete. looking into threading might be interesting.

      A Offline
      A Offline
      Ammar_Ahmad
      wrote on last edited by
      #22

      Err my laptops fan got fried - is at the repair shop. - sorry for the late reply... Anyway. So you mean I should just call this function on load? and replace the maxscroll = index - 18 on load?

      N 1 Reply Last reply
      0
      • A Ammar_Ahmad

        Err my laptops fan got fried - is at the repair shop. - sorry for the late reply... Anyway. So you mean I should just call this function on load? and replace the maxscroll = index - 18 on load?

        N Offline
        N Offline
        Nick Otten
        wrote on last edited by
        #23

        Hey, Sorry for my late response. I unfortunately fell ill. to get back to your question: No, you call that function every time after the amount of items in your flowlayoutpanel changes.

        A 1 Reply Last reply
        0
        • N Nick Otten

          Hey, Sorry for my late response. I unfortunately fell ill. to get back to your question: No, you call that function every time after the amount of items in your flowlayoutpanel changes.

          A Offline
          A Offline
          Ammar_Ahmad
          wrote on last edited by
          #24

          so all the code needs to be same. but what should I do with: maxscroll = index - 18 ? the index property was giving an error in flowlayoutpanel. can you give me the example on the same code or better on the project its self.. :

          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
          End Property
          
          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
          
          N 1 Reply Last reply
          0
          • A Ammar_Ahmad

            so all the code needs to be same. but what should I do with: maxscroll = index - 18 ? the index property was giving an error in flowlayoutpanel. can you give me the example on the same code or better on the project its self.. :

            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
            End Property
            
            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
            
            N Offline
            N Offline
            Nick Otten
            wrote on last edited by
            #25

            hmm oke i admid my code was a bit of mess. i cleared it out a bit and made a example program so you can see how it works. Please follow the below steps. 1. start a new form project 2. Add is Listbox. set the name to txtscroll and the size to 254; 381 3. Add a button, call this one btnadd 4. copy paste the following code into the project (under the form you just made)

            Imports System.Runtime.InteropServices

            Public Class Form1

            #Region "declarations"
            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
            Private index As Int32 = 0 'used for random loops to fill the txtscroll
            Private Const SB_HORZ As Integer = &H0
            Private Const SB_VERT As Integer = &H1
            #End Region

            #Region "dll calls"
            '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
            

            #End Region

            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
            
            A 1 Reply Last reply
            0
            • N Nick Otten

              hmm oke i admid my code was a bit of mess. i cleared it out a bit and made a example program so you can see how it works. Please follow the below steps. 1. start a new form project 2. Add is Listbox. set the name to txtscroll and the size to 254; 381 3. Add a button, call this one btnadd 4. copy paste the following code into the project (under the form you just made)

              Imports System.Runtime.InteropServices

              Public Class Form1

              #Region "declarations"
              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
              Private index As Int32 = 0 'used for random loops to fill the txtscroll
              Private Const SB_HORZ As Integer = &H0
              Private Const SB_VERT As Integer = &H1
              #End Region

              #Region "dll calls"
              '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
              

              #End Region

              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
              
              A Offline
              A Offline
              Ammar_Ahmad
              wrote on last edited by
              #26

              Alright so here is what I got so far:

              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
              ' Private index As Int32 = 0 'used for random loops to fill the txtscroll
              Private Const SB_HORZ As Integer = &H0
              Private Const SB_VERT As Integer = &H1

              '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
              
              
              Public Property HScrollPos() As Integer 'property to set or get the horisontal scrollbar value
                  Get
                      Return GetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB\_HORZ) 'change txtscroll to the control you use. dont forget the .handle
                  End Get
                  Set(ByVal value As Integer)
                      SetScrollPos(DirectCast(FlowLayoutPanel1.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(FlowLayoutPanel1.Handle, IntPtr), SB\_VERT) 'change txtscroll to the control you use. dont forget the .handle
                  End Get
                  Set(ByVal value As Integer)
                      SetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB\_VERT, value, True) 'change txtscroll to the control you use. dont forget the .handle
                  End Set
              End Property
              
              'will add load in the end.
              
              Private Sub FlowLayoutPanel1\_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlowLayoutPanel1.MouseWheel
                  scrollhandler\_MyScroll(e, e) 'needed to catch the scrollwheel event.
              End Sub
              
              
              Private Sub scrollhandler\_MyScroll(ByVal sender As Object, ByVal
              
              N 1 Reply Last reply
              0
              • A Ammar_Ahmad

                Alright so here is what I got so far:

                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
                ' Private index As Int32 = 0 'used for random loops to fill the txtscroll
                Private Const SB_HORZ As Integer = &H0
                Private Const SB_VERT As Integer = &H1

                '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
                
                
                Public Property HScrollPos() As Integer 'property to set or get the horisontal scrollbar value
                    Get
                        Return GetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB\_HORZ) 'change txtscroll to the control you use. dont forget the .handle
                    End Get
                    Set(ByVal value As Integer)
                        SetScrollPos(DirectCast(FlowLayoutPanel1.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(FlowLayoutPanel1.Handle, IntPtr), SB\_VERT) 'change txtscroll to the control you use. dont forget the .handle
                    End Get
                    Set(ByVal value As Integer)
                        SetScrollPos(DirectCast(FlowLayoutPanel1.Handle, IntPtr), SB\_VERT, value, True) 'change txtscroll to the control you use. dont forget the .handle
                    End Set
                End Property
                
                'will add load in the end.
                
                Private Sub FlowLayoutPanel1\_MouseWheelScroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FlowLayoutPanel1.MouseWheel
                    scrollhandler\_MyScroll(e, e) 'needed to catch the scrollwheel event.
                End Sub
                
                
                Private Sub scrollhandler\_MyScroll(ByVal sender As Object, ByVal
                
                N Offline
                N Offline
                Nick Otten
                wrote on last edited by
                #27

                It seems your making a mistake in providing the arguemnts for your max scroll.

                Quote:

                Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load scrollhandler = New MyListener(FlowLayoutPanel1) maxscroll = CalcMaxScroll(FlowLayoutPanel1.Size.Height, FlowLayoutPanel1.Size.Width, 114, 1075, 19) '19 number of tweets '114 height of tweettimelinecontrol '1075 width of flowlayoutpanel1 'last number tells the number of items. (read that from a global var) End Sub

                You say that the with of your flowlayoutpanel is 1075. yet you apply it to the formula as the with of your tweettimelinecontrol. quoting you from a previous post:

                Quote:

                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\[^\]

                you can see in the screenshot that you got 2 of those controls next to eachoter so it can never be the total size of your flowlayoutpanel. please check the with property of your Tweettimelinecontrol and change the value. while your at it also change the 19 with a flowlayoutpanel.items.count to make sure it are 19.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups