I created a composite control - called DateBox - that inherits from UserControl. It combines a DateTimePicker control (dateTimePicker1) together with a TextBox control (textBox1). In the designer, the textbox control is overlaid on the datetimepicker control so that you see the textBox and just the arrow of the datetimepicker. I can't get the following code to work, and I am not sure why:
void
dateTimePicker1_ValueChanged(object sender, EventArgs e){
this.textBox1.Text = this.dateTimePicker1.Value.ToShortDateString();
}
Can anybody help me? Thanks,
Jan MontanoPosted Aug 30, 2007, 2:19 AM
For the datetimepicker's height however, I don't know if it can be resized without changing the font size
AndyPosted Aug 29, 2007, 10:39 PM
Thanks, Jan. I got it to work. I think the Value_Changed event must have become unlinked, somehow. I am doing it this way so that I can also handle a user keying in six digits (e.g., 082907) in the textbox.
Followup question: Is there a way to change the height of a textbox control / datetimepicker control? If I try to change the property setting to say 25, it defaults back to 20.
Thanks again.
Jan MontanoPosted Aug 29, 2007, 10:12 PM
So far, it's working for me. I click on the datetimepicker to change the value and the textbox's value changes. During debug, does the program actually enters dateTimePicker1_ValueChanged() method? If not, are you sure that you have an eventhandler declared for it like the code below?
this.dateTimePicker1.ValueChanged += new System.EventHandler(this.dateTimePicker1_ValueChanged);
BTW, if you just need the textbox to change the display format of the datetimepicker, you could just change the Format property of DateTimePicker to Short instead, and drop the textbox.