Click here to Skip to main content
12,635,428 members (24,902 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

22.8K views
5 bookmarked
Posted

Manual Scroll Panel in a Panel or UserControl with AutoScroll=false

, 18 Feb 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Manual Scroll Panel in a Panel or UserControl with AutoScroll=false

https://www.codeproject.com/script/Membership/Uploads/3873871/4856575-ManualScroll.png

Introduction


This article show how to customize a System.Windows.Forms.Panel or a System.Windows.Forms.UserControl to use effectively scrollbars (ScrollProperties) without setting the AutoScroll property (you must not set AutoScroll=true). In most cases, you can use the AutoScroll = true. But in some cases, when you must work with two panels and separate Scrollbars, then you can use this ManualScrollPanel control. For example: if you will show 24 pictures just one by one on a scrollable panel, then you can set the Minimum of the VScrollProperties to 1 and the Maximum to 24. You can change Enable or Visible property of each scrollbar of the panel, receive a scrolling event, and change and receive the positions of both scrollbars.

Background


The Codeproject article "Customize a panel with Autoscroll property" by Manalee software gives the inspiration.

Using the Code


In your solution, add the file ManualScrollPanel.cs to your C# project. Then you can change type of a panel in your project by the ManualScrollPanel type. Now you can set the ScrollProperties values to the ManualScrollPanel (Enabled, Minimum, Maximum, SmallChange, LargeChange, Value, Visible) like you want.
In the example with the Form, you can see how the scroll is working.
Explanations about code in the ManualScrollPanel class:
First you must create a new class that overrides the System.Windows.Forms.Panel. In the constructor code, you must set the protected properties HScroll and VScroll to true. It is not possible to do this later on. You also must override the WndProc function to receive API32 scrolling messages (WM_HSCROLL, WM_VSCROLL). These messages must not pass to the base class. In WndProc was done a calculation for the new scroll value. If there is a new value then the ScrollEvent of the ManualScrollPanel was thrown.
That's all, enjoy with it in the hope that it will be useful for you...

History


Version 1.0 (Initial Release): All described features implemented. If you need the mousewheel, you have to do extra stuff.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

harbor
Retired
Germany Germany
I started programming with Fortran when I studied. I get experience with other languages (X86 Assembler, Turbo Pascal, Modula 2, C, C++, Delphi, C#, ...) on MSDOS, Windows and Embedded Realtime Systems.

Im my free time I work on a Midi- and Sound library and a music notation system programmed in C#.

You may also be interested in...

Comments and Discussions

 
Questionhow to Scroll Panel with autoscroll=false using visual studio toolbox Pin
kobayashi201323-Jan-13 15:39
memberkobayashi201323-Jan-13 15:39 
AnswerRe: how to Scroll Panel with autoscroll=false using visual studio toolbox Pin
harbor27-Mar-13 9:46
memberharbor27-Mar-13 9:46 
GeneralRe: how to Scroll Panel with autoscroll=false using visual studio toolbox Pin
kobayashi201328-Mar-13 15:44
memberkobayashi201328-Mar-13 15:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.161208.2 | Last Updated 18 Feb 2011
Article Copyright 2011 by harbor
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid