.NETGURU
Scrollbars
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Chris Smith
Experienced posters,

I am trying to sync the scrolling of to windows panel controls. Can someone
point me in the right direction?

Thanks,

Chris

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Chris Smith" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

The panel control supports scrolling of its content if the 'AutoScroll'
property is set to 'True'. Nevertheless, an event for handling the scroll
events is missing. This event can be added to the panel easily by deriving
from the 'System.Windows.Forms.Panel' class (or any other scrollable
control) and listening for scroll messages in the 'WndProc' method. The
code below can be used as a replacement for the .NET Framework's panel
control:

\\\
Imports System
Imports System.Windows.Forms

''' <summary>
''' Extends the panel control by a <c>Scroll</c> event.
''' </summary>
Public Class ScrollPanel
Inherits Panel

''' <summary>
''' Occurs when the panel is scrolled.
''' </summary>
''' <param name="sender">The source of the event.</param>
''' <param name="e">
''' A <c>ScrollEventArgs</c> that contains the event data.
''' </param>
Public Event Scroll(ByVal sender As Object, ByVal e As ScrollEventArgs)

Private Const WM_VSCROLL As Int32 = &H115
Private Const WM_HSCROLL As Int32 = &H114

''' <summary>
''' Raises the <c>Scroll</c> event.
''' </summary>
''' <param name="e">
''' A <c>ScrollEventArgs</c> that contains the event data.
''' </param>
Protected Sub OnScroll(ByVal e As ScrollEventArgs)
RaiseEvent Scroll(Me, e)
End Sub

Protected Overrides Sub WndProc(ByRef m As Message)
If m.Msg = WM_HSCROLL Then
OnScroll(New ScrollEventArgs(ScrollDirection.Horizontal))
ElseIf m.Msg = WM_VSCROLL Then
OnScroll(New ScrollEventArgs(ScrollDirection.Vertical))
End If
MyBase.WndProc(m)
End Sub
End Class

''' <summary>
''' Provides data for the <c>Scroll</c> event.
''' </summary>
Public Class ScrollEventArgs
Private m_Direction As ScrollDirection

''' <summary>
''' Creates a new instance of <c>ScrollEventArgs</c>.
''' </summary>
Public Sub New(ByVal Direction As ScrollDirection)
Me.Direction = Direction
End Sub

''' <summary>
''' Gets or sets the direction the panel has been scrolled to.
''' </summary>
''' <value>The direction the panel has been scrolled to.</value>
Public Property Direction() As ScrollDirection
Get
Return m_Direction
End Get
Set(ByVal Value As ScrollDirection)
m_Direction = Value
End Set
End Property
End Class

''' <summary>
''' Provides possible scrolling directions.
''' </summary>
Public Enum ScrollDirection

''' <summary>
''' Horizontal scrolling.
''' </summary>
Horizontal

''' <summary>
''' Vertical scrolling.
''' </summary>
Vertical
End Enum
///

'ScrollPanel' provides a 'Scroll' event that is raised when the panel is
scrolled. The event handler receives a 'ScrollEventArgs' object that gives
information about the scrolling direction.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Tom
Herfried : I need to do the exact same thing. I have two panels - when once
scrolls the other one has to be forced to scroll the same amount.

However, how did you figure how HOW MUCH to scroll the second panel? I.E.
Say your user scrolled the main panel by 50 pixels - how do you know how
much they scrolled and then scroll the other panel appropriately? This
control code seems to only tell you which way they scrolled, not how much
(or am I missing something).

Tom

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Tom" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

I never tested that, but you can check the panel's 'AutoScrollPosition'
in the first panel's 'Scroll' event and then set the 2nd panel's
'AutoScrollPosition' accordingly.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Tom
Herfried: Yep, after I wrote this message I did figure out that the
AutoScrollPosition.X and .Y show the amount of scrolling that the user did.
However, it seems these parameters are READ ONLY, which means that, although
I can get the direction and amount of scroll, I can't seem to figure out how
to make the other panel scroll by that same amount.

Got any ideas? Thx.

Tom

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Herfried K. Wagner [MVP] (VIP)
* "Tom" <Click here to reveal e-mail address> scripsit:
[Original message clipped]

\\\
Me.Panel1.AutoScrollPosition = Me.Panel2.AutoScrollPosition
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Reply to this message...
 
    
Tom
Herfried: Nope, I just tried that, and although VB.NET now accepts the
statement Panel1.AutoScrollPosition = ScrollPanel1.AutoScrollPosition
without any errors, it never sets it. I.E. Panel1 never scrolls when I
scroll ScrollPanel1. I know ScrollPanel1 is setting the proper
AutoScrollPosition because I see it via a Debug.Writeline statement;
however, setting Panel1.AutoScrollPosition = ScrollPanel1.AutoScrollPosition
does nothing. (even tried debug writing the Panel1.AutoScrollPosition after
setting it - still shows X=0; Y=0)

Any other ideas? This seems silly that there is no way to keep two panels
scrolling syncronized.... :-(

Tom

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:eS%Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Think_Fast
Tom, try this:

Panel2.AutoScrollPosition = New
Point(-Panel1.AutoScrollPosition.X, -Panel1.AutoScrollPosition.Y)

"Tom" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Tom
Hey that did the trick! I am not sure why the minus (-) sign makes the
difference, but it does.

Now, the only other issue I have is that although I want panel1 to be
autoscrolling, I -DON'T- want the scrollbars to show up. Do you know if any
way to make a panel be autoscroll and yet have no scrollbars? I know that is
an odd request but trust me, it is what I need to do in this screwy
applications case :-)

Otherwise I'll put this in another message on the forum.

Tom

"Think_Fast" <nospam@haha> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Chris Smith
Wow!

Thanks for the code. I got it to work like a champ.

"Herfried K. Wagner [MVP]" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Tom
Chris: I need to do the exact same thing (was just getting ready to write a
message when I saw yours!) I have two panels - when once scrolls the other
one has to be forced to scroll the same amount.

However, how did you figure how HOW MUCH to scroll the second panel? I.E.
Say your user scrolled the main panel by 50 pixels - how do you know how
much they scrolled and then scroll the other panel appropriately? This code
that Herfried gave only tells you which way they scrolled, not how much (or
am I missing something).

Tom

"Chris Smith" <Click here to reveal e-mail address> wrote in message
news:%234msh$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Diagnostics.Debug
System.Windows.Forms.Panel
System.Windows.Forms.ScrollEventArgs




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification