8
listbox.items.add(calendar.date.picked)
Quick and dirty
Instantiate the listbox control
ListBox lslBox = new ListBox();
// Add the system date mm/dd/yyyy
lslBox.Items.Add(DateTime.Now.ToShortDateString());
1
Hey if you are using MonthCalender control then use following code.
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{
listBox1.Items.Add(monthCalendar1.SelectionEnd.ToString());
}
0
Thank you very Much about your confirmation.
0
"...,so i use mouse click to choose the date then use button to add selected date to list box."
Much better idea :)
0
Your answer was perfect but it couldn't be use for month calender .
0
I changed my answer because when i was using mouse double_click compiler cannot distinguish the main purpose with other things,so i use mouse click to choose the date then use button to add selected date to list box.
What do you think about this way?
0
Which aspect are you not clear about?
0
Could you please explain more or using example please?
0
When a full month's calendar is displayed, the code should be selecting the date beneath the mouse when it is double clicked and then adding that date to the listbox, provided it hasn't been added previously.
At least, that's what it did when I tested it :)
Incidentally, it might be best to set the MonthCalendar's MaxSelectionCount property to 1 to ensure that there's no confusion with other dates that may be selected at the same time.
0
Thank you for your answer ,but your answer just add today date to the list box.
0
The MonthCalendar control doesn't expose the DoubleClick or MouseDoubleClick events.
However, you can manufacture you're own using the MouseDown event by calculating the time between events and seeing if it's short enough to be regarded as a double click:
private int lastTicks = 0;
private void monthCalendar1_MouseDown(object sender, MouseEventArgs e)
{
int currentTicks = Environment.TickCount;
if (currentTicks - lastTicks <= SystemInformation.DoubleClickTime)
{
string selected = monthCalendar1.SelectionStart.ToLongDateString();
if (!listBox1.Items.Contains(selected)) listBox1.Items.Add(selected);
}
lastTicks = currentTicks;
}
Note that double clicking on the month or a year also causes a selection to be made.
0
Could you please guide me?
0
Your answer wasn't correct,I think.
0
Your code just add today date to the list box,
although i want to add every date which i want for example my birth date to the list box.
Thank you
0
What is the problem?
0
It wasn't correct,I think.
Please Check it.
0
And your answer didn't add the date which has been chosen by user to list box .
0
I mean that when i double click on the left button of mouse on an special date in the mouth calender ,the current date automatically is added to list box.
-61
User ValueChaned event of datetimepicker as follows.
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
listBox1.Items.Add(dateTimePicker1.Value .ToString());
}