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

:)

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.

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

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.