Click here to Skip to main content
15,884,388 members
Articles / Mobile Apps / Windows Mobile

Implementing a smoothly animated ListBox

Rate me:
Please Sign up or sign in to vote.
4.94/5 (56 votes)
12 Jun 2008CPOL12 min read 403.1K   5.7K   156  
An article on creating an iPhone style ListBox.
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;

namespace Bornander.UI
{
    static class Utils
    {
        public static void SetHandlers(Control control, MouseEventHandler mouseDownEventHandler, MouseEventHandler mouseUpEventHandler, MouseEventHandler mouseMoveEventHandler)
        {
            control.MouseDown -= mouseDownEventHandler;
            control.MouseUp -= mouseUpEventHandler;
            control.MouseMove -= mouseMoveEventHandler;

            control.MouseDown += mouseDownEventHandler;
            control.MouseUp += mouseUpEventHandler;
            control.MouseMove += mouseMoveEventHandler;

            foreach (Control childControl in control.Controls)
            {
                SetHandlers(childControl, mouseDownEventHandler, mouseUpEventHandler, mouseMoveEventHandler);
            }
        }

        public static void RemoveHandlers(Control control, MouseEventHandler mouseDownEventHandler, MouseEventHandler mouseUpEventHandler, MouseEventHandler mouseMoveEventHandler)
        {
            control.MouseDown -= mouseDownEventHandler;
            control.MouseUp -= mouseUpEventHandler;
            control.MouseMove -= mouseMoveEventHandler;

            foreach (Control childControl in control.Controls)
            {
                RemoveHandlers(childControl, mouseDownEventHandler, mouseUpEventHandler, mouseMoveEventHandler);
            }
        }

        public static Point GetAbsolute(Point point, Control sourceControl, Control rootControl)
        {
            Point tempPoint = new Point();
            for (Control iterator = sourceControl; iterator != rootControl; iterator = iterator.Parent)
            {
                tempPoint.Offset(iterator.Left, iterator.Top);
            }

            tempPoint.Offset(point.X, point.Y);
            return tempPoint;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Software Developer (Senior)
Sweden Sweden
Article videos
Oakmead Apps Android Games

21 Feb 2014: Best VB.NET Article of January 2014 - Second Prize
18 Oct 2013: Best VB.NET article of September 2013
23 Jun 2012: Best C++ article of May 2012
20 Apr 2012: Best VB.NET article of March 2012
22 Feb 2010: Best overall article of January 2010
22 Feb 2010: Best C# article of January 2010

Comments and Discussions