954,148 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add DateTimePicker to ToolStrip ?

hi every one

i need help . How to add DateTimePicker to ToolStrip in my windows form ?

if any one can help

Nice Thanks,

IT_Techno

:)

IT_Techno
Light Poster
41 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

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:

private ToolStripControlHost dtTScomponent;

public form1()
{
            InitializeComponent();
            dtTScomponent = new ToolStripControlHost(dtMyDateTimePicker);
            MainToolStrip.Items.Add(dtTScomponent); 
}


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.

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

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:

private ToolStripControlHost dtTScomponent;

public form1()
{
            InitializeComponent();
            dtTScomponent = new ToolStripControlHost(dtMyDateTimePicker);
            MainToolStrip.Items.Add(dtTScomponent); 
}

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.

Thank you pal it work Correctly

IT_Techno
Light Poster
41 posts since Dec 2007
Reputation Points: 10
Solved Threads: 0
 

how i can do the same thing at visual basic
i have a visual studio 2005

mfahmy2008
Newbie Poster
5 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

it same...
here is the code for vb :

Private dtTScomponent As ToolStripControlHost
Public Sub New()
   InitializeComponent()
   dtTScomponent = New ToolStripControlHost(dtMyDateTimePicker)
   MainToolStrip.Items.Add(dtTScomponent)
End Sub
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

thank you very much about your reply
but how i can do the same thing at design time
you know of course the toolstrip only contain text label combobox button and not contain radio button datetimepicker etc

mfahmy2008
Newbie Poster
5 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

The only way I know of to do this at design time is to create a new component that is a subclass of ToolStrip, and then add the extra functionality. Use your new component instead of the ToolStrip.

// Jerry

JerryShaw
Posting Pro in Training
465 posts since Nov 2006
Reputation Points: 69
Solved Threads: 75
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You