Click here to Skip to main content
Click here to Skip to main content

A Time-Of-Day Picker control

By , 9 Dec 2002
 

Sample Image - TimeFrame.jpg

Introduction

This control uses double buffering to provide an interface that allows a user to choose time frames throughout the day. The control is modeled after a control that originally showed up in Windows NT, which allowed a user to specify valid login hours to the domain.

About the control

The control has a property called TimeFrames that returns a 3 dimensional array of TimeSpan objects.

public TimeSpan[][][] TimeFrames
  • The first dimension is the day
  • The second dimension is a specific contiguous time span
  • The third dimension will only have two elements, the first is the start time and the second is the end time

As suggested in the Eric White & Chris Garrett text "GDI+ Programming: Creating Custom Controls Using C#", all sections of the screen are split up into seperate objects. Since all major areas of the control can be hot tracked or selected, there is a base concept of a TimeFrameObject, which all sub areas inherit from. This base class includes members for the bounds of the object and whether the object is hot tracked or selected. This really cuts down on the code. For example, this method figures out where on the screen a particular point is and figures out which TimeFrameObject contains the point.

private TimeFrameObject GetTimeFrameObject( MouseEventArgs e )
{
    TimeFrameObject tfo = null;
    if( Grid.Contains( e.X, e.Y ) )
    {
        tfo = CellMatrix[ (int)( ( e.Y - Header ) / y_grid_inc), 
                (int)( ( e.X - LeftMargin ) / x_grid_inc) ];
    }
    else if( ( e.X > Grid.X ) && ( e.X < 
            ( Grid.X + Grid.Width ) ) && ( e.Y < Grid.Y ) )
    {
        tfo = (TimeFrameObject)
            TimeSlots[ (int)( ( e.X - LeftMargin ) / x_grid_inc) ];
    }
    else if( ( e.X < Grid.X ) && 
            ( e.Y < ( Grid.Y + Grid.Height ) ) && ( e.Y > Grid.Y ) )
    {
        tfo = (_Day)Days[ (int)( ( e.Y - Header ) / y_grid_inc) ];
    }
    else if( TopLeft.Contains( e.X, e.Y ) )
    {
        tfo = TopLeft;
    }
    return tfo;
}

This reduces OnMouseDown to:

protected override void OnMouseDown( MouseEventArgs e )
{
    TimeFrameObject tfo = GetTimeFrameObject( e );
    if( tfo != null )
    {
        if( e.Button == MouseButtons.Left )
        {
            tfo.Selected = ! tfo.Selected;
            tfoLastSelected = tfo;
            this.Invalidate( true );
        }
    }
}

That's all

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

ClearlyDotNet
Web Developer
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralSmall UpdatememberAngelo Cresta9 Jul '09 - 21:28 
GeneralAdd a vertical or horizontal scrollbarmemberJudyll11 Nov '07 - 4:24 
QuestionSample code VB.NET?memberpclady28 Nov '06 - 18:00 
Generalread graphical framemembercrisyuri2 Feb '06 - 12:47 
QuestionLoad Data Failed? Anyone can help me?memberxiaohu15 Jan '06 - 17:47 
GeneralLoading Datamemberdietsche9 Apr '05 - 9:45 
QuestionHow to migrate to WebForm?memberXTV27 Sep '04 - 22:27 
Hi; your control it's very usefull, and I need something similar for use in the web.
 
How can I migrate this control to WebForms? Confused | :confused:
 
Thanks Smile | :)
GeneralIt's genious!memberelmotheelk17 Aug '04 - 1:33 
GeneralTwo TImeFramememberJianhua Cao11 Aug '04 - 9:56 
GeneralRe: Two TImeFramememberJianhua11 Aug '04 - 10:04 
GeneralRe: Two TImeFramememberfatcat111117 Feb '05 - 13:00 
GeneralRe: Two TImeFramemembertony16161612 Feb '06 - 0:38 
GeneralDid anyone manage to solve loading dataset into the controlmemberchrisybhot128 Apr '04 - 22:56 
Generalgetting this party startedmemberkvc25 Jul '03 - 3:36 
GeneralRe: getting this party startedmemberamun10026 Oct '09 - 23:37 
GeneralTimeSpans vs. DateTimememberHeath Stewart20 Jan '03 - 8:12 
GeneralRe: TimeSpans vs. DateTimememberClearlyDotNet30 Jan '03 - 7:40 
GeneralNice!memberTim Hodgson16 Jan '03 - 4:33 
QuestionCool Control . but how to load data ?memberscryer2117 Dec '02 - 0:03 
AnswerRe: Cool Control . but how to load data ?memberClearlyDotNet30 Jan '03 - 7:44 
GeneralRe: Cool Control . but how to load data ?memberxavier213 Feb '03 - 7:02 
Generalbut how to load data ?membermaartensmolders7 Apr '03 - 1:21 
GeneralRe: but how to load data ?memberdl4gbe29 Nov '04 - 6:05 
GeneralRe: Cool Control . but how to load data ?membercmpenney13 Oct '08 - 6:09 

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 10 Dec 2002
Article Copyright 2002 by ClearlyDotNet
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid