DateTimePicker Value/Text properties
I made a DateTimePicker control with readonly functionality using a Textbox control drawn at the same place as the DTP control when in readonly mode.
I've overridden (amongst others) the OnValueChanged Method, and there I put "_textBox.Text = this.Text". This all works fine, unless my control is in ReadOnly mode when my form pops up (or when the DTP control is on another tabspage, when the Form pops up).
In that case, "this.Text" is always empty. Does this has something to do with te painting? I'm out of inspiration...
Any suggestions/solutions ?
TIA,
Fretje
[628 byte] By [
Fretje] at [2007-12-16]
The DateTimePicker control's Text is blank if the underlying wrapped control's handle is not created. You should be able to work around this by adding the following to your DateTimePicker sub-class OnValueChanged override:
| | if (!this.IsHandleCreated) { this.CreateHandle(); } |
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
This indeed was the solution for this problem!
I solved it in a more generic way by overriding the Text Property like this:
| |
public new string Text { get { if (!this.IsHandleCreated) { this.CreateHandle(); } return base.Text; } set { base.Text = value; } }
|
But shouldn't that be in the base DateTimePicker class?
If someone asks for the text in the control, the text is what should be returned, and not an empty string in some cases...
Anyways, many thanks!
Fretje