private void strDate(string strFormat,DateTime givendate) { try { date = givendate; listBox1.Items.Add(String.Format("{0:" + strFormat + "}", date)); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { strDate(textBox1.Text, dateTimePicker1.Value); }