Jump to content
Xtreme .Net Talk

Recommended Posts

  • *Experts*
Posted

Hi,

I'm having a problem programmably increasing a panel's AutoScrollPosition. With the lower code, the auto scroll vibrates up and down instead of progressing constantly downward.

 

   Private Sub bkrTemp_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles bkrTemp.MouseMove

       Dim pt As Point
       pt.X = Me.PointToClient(Cursor.Current.Position).X - x
       pt.Y = Me.PointToClient(Cursor.Current.Position).Y - y
       With bkrTemp
           .Location = pt
           .Capture = True
       End With

       If pnlPanel.AutoScroll = True Then
           Dim bkrLocY As Integer = bkrTemp.Location.Y - (pnlPanel.Location.Y + pnlPanel.AutoScrollPosition.Y) + bkrTemp.Height
           Dim pnlHeight As Integer = pnlPanel.Height - (pnlPanel.AutoScrollMargin.Height + 17)

           If bkrLocY + 2 >= pnlHeight Then
               pnlPanel.AutoScrollPosition = New Point(pnlPanel.AutoScrollPosition.X, pnlPanel.AutoScrollPosition.Y + 5)
           End If
       End If
   End Sub

 

How can I have pnlPanel scroll constantly downward with bkrTemp?

 

Thanks,

Dan

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

  • Leaders
Posted

I ran into a very similar problem recently. The AutoScrollPosition property is pretty quirky. When you get the AutoScrollPosition is returns how much the view has moved, i.e. {10, 20} would be scrolled right ten and down twenty. When you set it, you need to specify how far the controls should be moved. If you are scrolled ten right and twenty down, the controls have moved ten left and twenty up on the screen, which means that you would want to set AutoScrollPosition to {-10, -20} to set it to that same position.

 

I'm guessing that this is a bug. I believe that the solution is to negate the value immediately before assigning it (if you want to think in terms of where the view port is... if you want to think in terms of how far the controls have moved, negate the value as soon as you obtain it). For example, to move the AutoScrollPosition down and right fifty pixels, you would use the following code:

Dim View As Point = MyPanel.AutoScrollPosition
View.X = -(View.X + 50)
View.Y = -(View.Y + 50)
MyPanel.AutoScrollPosition = View

I didn't test that code, but something like that should do the trick.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...