By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,281 Members | 2,216 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,281 IT Pros & Developers. It's quick & easy.

autoscroll

P: n/a
Hello,
if autoscroll is true in a form. Is there a way to detect the scrollbars are
active?
Thanks
Frank
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
* "Frank" <fr***@frank.com> scripsit:
if autoscroll is true in a form. Is there a way to detect the scrollbars are


You can base your implementation on this sample to intercept scrolling:

\\\
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
I am not sure what you mean by by 'detect the scrollbars are active' but
here are two bits of info that might apply.

1. To determine if scroll bars are enabled test the form's AutoScroll
property.

If myForm.AutoScroll = True
MessageBox.Show("Scroll bars are active.")
End IF

2. To determine if the form has been scrolled from its original position
test the form's AutoScrollPosition.

If MyForm.AutoScrollPosition.X = 0 And MyForm.AutoScrollPostion.Y = 0 Then
MessageBox.Show("Form has been scrolled away from its base position.")
End If
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"Frank" <fr***@frank.com> wrote in message
news:ch**********@news2.tilbu1.nb.home.nl...
Hello,
if autoscroll is true in a form. Is there a way to detect the scrollbars are active?
Thanks
Frank

Nov 21 '05 #3

P: n/a
Thanks Mike,
but this is not what I am looking for. Your test on 'autoscroll is true'
only shows that autoscrolling is enabled, not that the bars are actually
showing.
If no scrollbars are necessary they are not shown. If scrolling is needed,
autoscroll enabled will provide the bars automatically. I want to know
whether the bars are shown or not.
Regards
Frank

"Mike McIntyre [MVP]" <mi****@dotnetshowandtell.com> wrote in message
news:ex**************@tk2msftngp13.phx.gbl...
I am not sure what you mean by by 'detect the scrollbars are active' but
here are two bits of info that might apply.

1. To determine if scroll bars are enabled test the form's AutoScroll
property.

If myForm.AutoScroll = True
MessageBox.Show("Scroll bars are active.")
End IF

2. To determine if the form has been scrolled from its original position
test the form's AutoScrollPosition.

If MyForm.AutoScrollPosition.X = 0 And MyForm.AutoScrollPostion.Y = 0 Then
MessageBox.Show("Form has been scrolled away from its base position.")
End If
--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com

"Frank" <fr***@frank.com> wrote in message
news:ch**********@news2.tilbu1.nb.home.nl...
Hello,
if autoscroll is true in a form. Is there a way to detect the scrollbars

are
active?
Thanks
Frank


Nov 21 '05 #4

P: n/a
Herfried, thanks for the reply, but as far as I understand your coding it
only shows that the user is scrolling. I want to know whether the scrollbars
are actually shown, or that the formcontrols fit in the window and the
scrollbars are not visible (not needed).
I can't find a way and searching internet didn't provide an answer. I guess
I am the first having this problem.
Thanks
Frank
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2q************@uni-berlin.de...
* "Frank" <fr***@frank.com> scripsit:
if autoscroll is true in a form. Is there a way to detect the scrollbars
are
You can base your implementation on this sample to intercept scrolling:

\\\
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5

P: n/a
The solution is to use the HScroll and VScroll properties. From the
help...

---
Gets or sets a value indicating whether the horizontal scroll bar is
visible.
---

Unfortunately these are protected properties, so if you want to expose
them publicly you will need to subclass whatever it is you are using,
e.g. Form, UserControl, etc. and add in a new property that passes
through the protected value.

I checked it and it works. Now whether AutoScrollMinSize is the actual
size of the scrollbar is another matter :)

Colin Green
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.