DateTimePicker - Which subfield has focus? - c#

I have a class that derives from DateTimePicker. The picker control has format set to DateTimePickerFormat.Custom and custom format string set to yyyy.MM.dd HH:mm in order to display dates in the format 2013.01.25 21:45. Here, 2013 is the year subfield that gets highlited when the users clicks on it with the mouse cursor or tabs to it using the TAB key. Once highlited, the user can use UP/DOWN keys to increment / decrement the year, or manually enter a new year value. The same holds true for the month, day, hour and minute subfields.
For my application, certain dates or time values are forbidden. For instance, consider the following rule:
An appointment can only be scheduled at a time rounded to the nearest 10 minutes. For instance, you can schedule one at either 21:10 or 21:20, not at 21:13.
For this, I need to know which subfield currently has focus. The problem is I don't know how to determine this. If I know which subfield has focus, I could devise the following set of rules in code.
If the minute subfield is selected, and the user presses the UP key, increment the time by 10 minutes.
If the minute subfield is selected, and the user presses the DOWN key, decrement the time by 10 minutes.
If the minute subfield has lost focus, round the minutes up or down to the nearest 10 minutes.
The only problem that remains.. HOW DO I FIND WHICH SUBFIELD CURRENTLY HAS FOCUS?
NOTE: Yes I can make validation checks in OnLeave event but the my application requires that invalid datetime values be skipped altogether. Also, I have checked out the solution given here. But I am inclined to find the active subfield as an exercise as well. Finally, if its of any use, I'm using C# 4.0 on Windows 7 x86.

Related

C# Countdown Timer to chosen date from now

SharpDevelope / WPF Application
For now i got a working program.
What does it do?
It‘s a gridlistview with several entries for reminders.
Columns as followed:
Entry time / date / time / case / description / priority / name who entered / case closed? (as combobox)
So my actual problem:
I want to implement a countdown timer function to the given date and time.
So if someone check the combobox(to create a countdown) while making an entry, the program should create a timer.
I searched several threads here and on other sites, but cant find a good solution.
What should it do when button „add entry to list“ is pressed and the „create timer“ combobox is checked?
Create timer from the date.textbox and time.textbox combined (i cant get it right for a valid datetime). So for me it would be "dd.MM.yyyy HH:mm:ss".
Then substract the combined date from timeNow() and display the remaining time till 0 in a textbox beside the gridview.
I don't know if it would be to much if there are xxx amounts of timers created by entries.

C# Datetimepicker Way to Stop Validation

I have a datetimepicker with format dd.MM.yyyy when i have, for example, date 14.02.2011, save it and then want to enter 31.12.2011 then datetimepicker validator doesnt allow me to enter 31 because of month 02 inside,so it set automatically 29 in the datetimepicker.
In this case, i have to go to change a month and then back to change a day, is there a way to switch off this validation?
You have set a Value (DateTime) for the control and are now trying to change its elements one at a time, such that an intermediate value is invalid.
Assuming you are talking about the .Net Framework class (System.Windows.Forms), before capture (re)starts, you can use the ResetText() method or set the Value or Text property to an appropriate starting value for your use case. Otherwise, instead of allowing separate editing of Value.Day, .Month and .Year, capture the full text representation of the date and update the control's Text property afterwards.

How to restrict text entry on Kendo Angular Date Picker?

Kendo's Angular Date Picker, restricts the date selection using [min] and [max] to select date from the UI. However, for text entry (user types in the date instead of selecting from the datepicker) user is restricted to enter months above 12 and dates above 30/31 accordingly. But, I need to restict user to type the year as well. Suppose if user types 1996 and my max year is 1995, the date year should change to 1995.
You can make one function which triggers when date is changed, this function should check if your requirements are satisfied with newly entered date OR it should revert back to last value . The Benefit of this approach is that user still can type the values but still it should be inside your validation range.

Xaml DatePicker default and earliest date available for selection settings in C#

I have couple of datepicker implemented in Xaml .
- After user picks certain dates, a simple logic finds the earliest of the two dates. Also, it is not necessary for user to pick both dates.
I noticed that the "default" datepicker value if user does not pick any date is 1/1/0001.
Assuming the user picks the second date as 1/1/2017, the earliest of the two dates would always be 1/1/0001 which is not desired. In such scenario, the minimum date should be 1/1/2017.
what is the logic to neglect default date of 1/1/0001
There is a property MinYear which can be set to minimum year accepted which in your case obviously should be 2017. This will solve the problem by automatically limiting range of available values to be lower bounded by 2017-01-01 - this for UWP DatePicker.
In WPF DatePicker there is a DisplayDateStart property which can be set to minimum date available in drop down calendar which can be chosen by user. Similar property DisplayDateEnd is used for setting highest date which can be displayed in DatePicker. DatePicker.SelectedDateChanged is a very useful event which when wired up will capture changes to the dates on all instances of DatePickers and this can be used to create relations between them i.e. to enforce selection of the valid period which starts from date selected on DatePicker 1 and ends on date selected in DatePicker 2 by setting DisplayDateStart on picker 2 to date selected on picker 1 in event handler. This all together provides very high level of flexibility in controlling user input via DatePicker class.

C# Datetimepicker : Set forecolor to Specific Date

I am using a datetimepicker in my application. I want it to display specific dates (in this case, all Holidays of a month) with one specific color (i.e. The holidays will be shown as red or blue or any color) when the datetimepicker is clicked and its monthview (i don't know exact name of this) is prompted. Is it possible with default datetimepicker ?
Suppose there are holidays in August are all the public holidays (in this case, every fri and sat) and some specific holidays (such as 13 Aug,19 Aug etc) and I want to show them in red/blue color. This will also occur when I change the month to September (or any month).
I shall bring the holidays from database where I keep my holiday records.
Thanks in advanced.
A longer time ago i had to do similar solution for a busines Application.
you might wanna look at http://msdn.microsoft.com/en-us/magazine/dd882520.aspx
i don't think i can sum it up better than this site.
Look at "Figure 8 The RedLetterDays Display". Sounds like the thing you need.
greetings

Categories