Forum Discussion

MulgraveTester's avatar
MulgraveTester
Frequent Contributor
9 years ago

Navigate to Hours section of a DateTimePicker time field

I want to set the time of a DateTimePicker using a similar method to what a user would enter. i.e. I want to use the keys method and I don't want to set the wTime property programmatically.   The p...
  • Colin_McCrae's avatar
    Colin_McCrae
    9 years ago

    Hmmm.

     

    I don't have one to hand to play about with.

     

    But ....

     

    You can set focus to it. So you know it is the active control.

     

    You can get it's height/length. (And also relative co-ordinates to the screen and parent control if required)

     

    So you *could* apply a mouse click around 5 pixels in from the left edge of the control (at half height)? It appears to be left aligned, so that would cause it to always move focus to the hours part I would think? At 5 pixels, I don't think there is any danger of going too far right and ending up in the minutes section instead.

     

    And as you have all the sizes and relative co-ordinates, you can make use of these so that it tracks it if it moves or the application is opened in a different area of the screen.

     

    I know using co-ordinates doesn't sound ideal. But in some cases (like this) it's OK as long as you control it properly and have known parameters to act as anchors and you do your co-ordinate based clicks relative to these.

     

    I have to do it for a few custom controls myself. Mainly as that's how the controls are built! (eg. A tree with checkboxes that has an event trigger which is activated by a mouseclick on the tree object where the checkbox is positioned! Crazy, but that's how they did it, so that's how I have to do it ...)