Click here to Skip to main content
15,881,089 members
Articles / Desktop Programming / Windows Forms

Simple Carousel Control for Windows Forms

Rate me:
Please Sign up or sign in to vote.
3.33/5 (7 votes)
24 Apr 2012CPOL2 min read 59.2K   8K   31   4
Simple Carousel Control for Windows Forms, can host any content with in views.
Carousel_WinForm/Preview.png

Introduction     

Its always fun to create something elegant and interactive, and Carousel is the best example to present contents this way. I guess telerik is the only vendor to offer Carousel control for Windows Forms, and that's why Carousel in window forms, with WPF we can achieve a more elegant transitions and a better rendering, and code project has 2D and 3D carousels in WPF.  

Background  

Transitions in this article is handled by the use of IntAnimation in my previous article, it is recommended to take a look at the Animate Properties in Windows Forms before beginning with the carousel control. 

Using the code 

View :  

Every item visible in the  Carousel is a View, and is derived from Panel therefore can host any content.

Carousel: 

Carousel is derived from Control, and has these following public members.

ActiveView :  A reference to the active View.

ViewMargin  : Gets or sets the space between the Carousel and the Views.

ViewOffset : Gets or sets the spacing between adjacent views. 

ViewPortItemsCount : Gets or sets the number of Views visible within view port. 

Views : Gets or sets the views associated with the Carousel. 

Adding Views 

By clicking the ellipsis button available in the Views property for the Carousel 'View Collection Editor' can be invoked and you can add views to the carousel. Carousel produces best look and feel with the odd number of views.  

How It works     

Carousel operates on very simple principle, Views are laid out with in the view port, and the view in the middle is initialized as active, 

 Carousel_WinForm/Representation.png

Assume the views are in circular list (Literally are in CircularList) , when a view is activated other views are shifted to the left / right depending on the relative position with the active view. 

 Carousel_WinForm/Representation1.png

This transition is handled with the help of IntAnimation as follows.

C#
IntAnimation Xanimation = new IntAnimation
			{
			 By = 1,
			 Interval = 1,
			 Duration = animOffset * 10,
			 From = view.Left,
			 To = animOffset,
			};

view.Animate("Left", Xanimation);

History   

24 Apr, 2012 - Amended. Removed leading spaces from paragraphs.

14 Nov,2011 - Initial Post. This article is just to open up the world of possibilities with the Animation Framework,  This version of Carousel is a simple implementation, do let me know if you have any requirements to be added further.

 Happy Coding!!! 

License

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


Written By
Technical Lead
India India
I code, learn, read and listen.

Comments and Discussions

 
QuestionGetting error when compiling the solution in VS2019 Pin
Y Kiran Kumar16-May-20 5:47
Y Kiran Kumar16-May-20 5:47 
Questioncan't load metrics.dll to reference Pin
GoyalGourav20-Jan-13 19:42
GoyalGourav20-Jan-13 19:42 
hi,
I am trying to add metrics.dll to my reference folder, but it dhows warning sign. Please help

Thank You
Gourav Goyal
GeneralMy vote of 2 Pin
Sacha Barber30-Nov-11 4:47
Sacha Barber30-Nov-11 4:47 

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.