First, the demand preface
In the report development process, often with the year or month as the query criteria, and currently under the WinForm platform, there is no complete direct availability of the year or month selection control can be used, for this, in the development or the following drop box fill year data, etc. as a workaround, The implementation is not only cumbersome but also slightly unchanged to use. How to develop a better use of the year and month selector? Today, I'm going to use the Dateedit control as the base control, to construct a more practical year and month selector control for everyone.
Second, the need to solve
1. In the VS left-hand toolbox, drag a Dateedit control to UserControl
In fact, the Dateedit control is essentially a combination of a text editor and a calendar drop-down box, so when we build the new controls, we also need to set the two seed editor separately.
2. Set Dateedit Control text sub-editor properties
The text sub-editor can be divided into the display state and the editing state, and the focus is not on the control, the Dateedit is in the display state, and when the focus is dateedit the text is in the edit state. If you want to display the year or month, you need to set these two sub-attributes. Now, as an example of year display and edit, these two properties are set up in the following way:
Display state: Formattype Select Custom, that is, to customize the type, formatstring fill in the yyyy. That is, only 4-bit years are displayed
Edit state: Editmask fill in the yyyy. That is, only 4-bit years are displayed
3, Calendar drop-down box settings. The Vistacalendarviewstyle property is the display type of the calendar panel. The default is all. A full display of the year list, year, month, date, and so on. If you want to make a year selector. Then change this property to Yearsgroupview. Remove all other options to check the status
At this point, a simple and useful year selection control is born. The effect is as follows:
Construct a simple and useful year and month selector