ToolStripControlHost & DateTimePicker
- From: "Brian Sokolnicki" <brians@xxxxxxxxxx>
- Date: Thu, 10 Aug 2006 13:42:59 -0500
I'm trying to display a datetimepicker control on a toolstrip and with the
code provided below, using the vs2005 designer, I see the control as an
option for the toolstrip, but when I select it, it looks like it adds it
then disappears. Can anybody help by looking at the code below and seeing
if I did something wring. Thanks.
#region Using directives
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
#endregion
namespace MicroTek.RMS.UserControls
{
//Declare a class that inherits from ToolStripControlHost.
[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.ToolStrip)]
public class ToolStripDateTimePicker2 : ToolStripControlHost
{
// Call the base constructor passing in a DateTimePicker instance.
public ToolStripDateTimePicker2()
: base(new DateTimePicker())
{
((DateTimePicker)this.Control).Format = DateTimePickerFormat.Short;
((DateTimePicker)this.Control).Width = 90;
}
public DateTime SelectedDate
{
get { return ((DateTimePicker)this.Control).Value; }
set { ((DateTimePicker)this.Control).Value = value; }
}
protected override void OnSubscribeControlEvents(Control c)
{
base.OnSubscribeControlEvents(c);
((DateTimePicker)c).ValueChanged += new EventHandler(OnDateChanged);
}
protected override void OnUnsubscribeControlEvents(Control c)
{
base.OnUnsubscribeControlEvents(c);
((DateTimePicker)c).ValueChanged -= new EventHandler(OnDateChanged);
}
public event EventHandler DateChanged;
protected void OnDateChanged(object sender, EventArgs e)
{
if (DateChanged != null)
DateChanged(this, e);
}
}
}
.
- Follow-Ups:
- RE: ToolStripControlHost & DateTimePicker
- From: Linda Liu [MSFT]
- RE: ToolStripControlHost & DateTimePicker
- From: Linda Liu [MSFT]
- RE: ToolStripControlHost & DateTimePicker
- Prev by Date: Re: Messagebox in Validating cancels subsequent events
- Next by Date: Re: Messagebox in Validating cancels subsequent events
- Previous by thread: Messagebox in Validating cancels subsequent events
- Next by thread: RE: ToolStripControlHost & DateTimePicker
- Index(es):