View Single Post
Join Date: Nov 2006
Posts: 436
Reputation: JerryShaw is on a distinguished road 
Solved Threads: 72
JerryShaw JerryShaw is offline Offline
Posting Pro in Training

Re: How to add DateTimePicker to ToolStrip ?

 
0
  #2
Feb 20th, 2008
You can place just about anything on the toolstrip.
First (in the IDE) place the desired component on the form (anywhere will do).
Provide yourself with a ToolStripControlHost type variable.
Then when the form in instantiated, do this:
  1.  
  2. private ToolStripControlHost dtTScomponent;
  3.  
  4. public form1()
  5. {
  6. InitializeComponent();
  7. dtTScomponent = new ToolStripControlHost(dtMyDateTimePicker);
  8. MainToolStrip.Items.Add(dtTScomponent);
  9. }

dtMyDateTimePicker is the component you dropped on the form, and eventually want to live on the tool strip. The hosting variable is instantiated and takes dtMyDateTimePicker as its child. When the new host is added to the toolstrip, the datetime picker goes with it.
You can set the properties of the toolstrip collection and the dtTScomponent properties to get the desired appearance. From that point on, you do not need to refer to the dtTScomponent for anything... it is just a host.
Reply With Quote