.net c# text box date with mask - setup - c#

I have a c# .net project and want an input text box for a date value. I want it to display a default value of mm/dd/yyyy and then allow users to enter valid dates.
I have tried using a masked text box but it doesn't like having the above format.
If i try and use //____ looks naff and so does 00/00/0000 and of course if you put in '0' like 03/11/2009 you get 3/11/29 because the 0's are deleted as part of the mask.
What is the best way to set up an input box like this, effectively with a mask, only allowing numbers, and validation (though at this point I am not so worried about that).
This seems so simple and isn't.

Try examining the the date in the OnChange event. Check the length of the text, adding / when appropriate.
Alternatively, see if the the DatePicker may be a better choice...

Why not try and use a plugin like the jQuery UI DatePicker?
http://docs.jquery.com/UI/Datepicker
They are lightweight, tested and saves work!

Assuming Windows Forms, the DateTimePicker is the tool for the job.
Here is an example with the MaskedTextBox, but since you say it doesn't work...
Another good try, if you're using DataBinding, if by instantiating a Binding (Binding for WPF) class and handling its Parse and Format events (these don't seem to exist in WPF, but there must be some way).
In short:
Binding b = new Binding("Text", BindingSourceInstance, "data.DateCreated");
b.Parse += new EventHandler(b_Parse);
b.Format += new EventHandler(b_Format);
private void b_Format(object sender, ConvertEventArgs e) {
if (e.DesiredType != typeof(DateTime)) return;
e.Value.ToString("dd/MM/yyyy");
// Or you may prefer some other variants:
// e.Value.ToShortDateString();
// e.Value.ToLongDateString();
// e.Value.ToString("dd/MM/yyyy", CultureInfo.CurrentCulture.DateTimeInfo.ShortDatePattern);
}
private void b_Parse(object sender, ConvertEventArgs e) {
// Choose whether you to handle perhaps bad input formats...
e.Value = DateTime.Parse(e.Value, CultureInfo.InvariantCulture); // The CultureInfo here may be whatever you choose.
}

Using masked text box for date is a headache, best to use DateTime.TryParseExact() with control validated event.
It will guarantee user input in correct format without too much coding, like in this example:
you need to use also a ToolTip to instruct the user to the correct input.
private void txtEntryDate_Validated(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtEntryDate.Text))
{
DateTime entryDate;
if (DateTime.TryParseExact(txtEntryDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out entryDate))
{
// further actions for validations
}
else
{
setTooltip(txtEntryDate, "txtEntryDate", "Invalid date format date must be formatted to dd/MM/yyyy");
txtEntryDate.Focus();
}
}
else
{
setTooltip(txtEntryDate, "txtEntryDate", "Please provide entry date in the format of dd/MM/yyyy");
txtEntryDate.Focus();
}
}
and the ToolTip class:
private void setTooltip(Control Ctrl, string CtrlCaption, string ToolTipMsg)
{
ToolTip tt1 = new ToolTip();
tt1.AutoPopDelay = 5000;
tt1.InitialDelay = 1000;
tt1.ReshowDelay = 500;
tt1.ShowAlways = false;
tt1.SetToolTip(Ctrl, CtrlCaption);
tt1.Show(ToolTipMsg, Ctrl,5000);
}

Related

DateTime array element does not contain the correct value

I've created a simple DateTime array that contains 3 items. These items are set to use the values of three different DateTimePickers on my form. Before I go further into using the array, I need to make sure it is actually using the correct values, and it does not appear to be doing so. Here's my code:
namespace Test
{
public partial class Form1 : Form
{
DateTime[] monSchedule = new DateTime[3];
public Form1()
{
InitializeComponent();
monSchedule[0] = monStart.Value;
monSchedule[1] = monEnd.Value;
monSchedule[2] = monLunch.Value;
}
private void Form1_Load(object sender, EventArgs e)
{
setDefaults();
}
private void setDefaults()
{
monStart.Value = DateTime.Parse("00:00");
monEnd.Value = DateTime.Parse("00:00");
monLunch.Value = DateTime.Parse("00:00");
}
private void validate()
{
MessageBox.Show("You entered time " + monSchedule[0]);
}
When I load my form, setDefaults(); should change the values to the current date with a time of 00:00. When I press the button to show the value in the array, it is pulling current date and current time. I need it to pull whatever the current time in that DateTimePicker is. So if a user types 10:00 into the DateTimePicker (they are formatted HH:mm), then I need the MessageBox to say the time is 10:00 AM. If I change the value to 22:00, then I need the messagebox to say the time is 10:00 PM. etc. (Date is irrelevant in my scenario, I'm not concerned with what the date is at all. Only the time.)
I suspect it may be because of the order it's written in. Is the array storing the value of the DateTimePicker BEFORE setDefaults(); is run? If so, how do I make the values of the array items dynamic since the values of the DateTimePickers are going to change a lot and I need the array elements to be updating with the latest values?
EXTRA INFO:
-Using Visual Studio
-Added the DateTimePickers in design view, changed the format to HH:mm there, did not change the default values in design view
-Ignoring date completely, only concerned with time right now
PS: I was also struggling with where to declare the array so it was accessible in multiple other methods and found I had to declare the array initializer within public partial class Form1, but then add the items in the array within public Form1(), because it wouldn't let me add them under public partial class Form1. I don't know if this is correct though, but it seemed to work when I tested with an array of strings so I went with it.
I have to say that this is a bit of a regression. In your previous question, JoshPart gave you good advice in the form of user controls, although he may have left some gaps too large for you to fill on your own.
Using arrays in this manner might work for a single day, but it won't scale well to a full week.
In case anyone reading this is wondering why I'm talking about a full week, I refer you to the previous question. Also, I recognize that I'm going off-topic for this specific question but I believe this to be an XY problem and the previous question was actually based on the real problem and work that was more on-the-mark.
Let's start with what we know. I've gleaned this from the two questions and the various comments in both.
You have DateTimePicker controls for start, end, and lunch. You're only interested in the time portion so you have Format set to "Custom" and CustomFormat set to "HH:mm". Assumption: lunch is a fixed length so the end time isn't needed.
You have the aforementioned controls times seven, one set for each day of the week.
You've written validation code (range tests) to determine if values are entered correctly, and you're able to show a label with red exclamation marks when that test fails.
You've identified that it's getting too complicated just having a bunch of controls on a form.
So far, so good. Now for your goal.
You're looking for a way to organize the controls, and the data they collect, to make it easier to work with them.
A user control is still the way to go here. You'll benefit from encapsulating all that repeated functionality into a single place and being able to reuse it.
Start by creating a user control -- we'll call it DayPanel -- and put all the controls for a single day on that canvas. Name the controls without any regard for the day of week (e.g. start, lunch, and end). Your user control will neither know nor care which day it represents.
Add an event handler for the ValueChanged event to the DateTimePicker controls. Instead of double-clicking the control, go to the events list in the Properties tool window and type a name, such as the one below, for the ValueChanged event. Do the same for the other two controls and it will reuse the event handler that it created the first time. Whenever the user changes a time, this event handler will be called and it will effect changes to the UI.
private void picker_ValueChanged(object sender, EventArgs e)
{
// In case you need to know which DateTimePicker was changed, take a look at 'sender':
//DateTimePicker picker = (DateTimePicker)sender;
UpdateWarningState();
}
As Jimi mentioned, the sender object will be a reference to the DateTimePicker control that sent the event. You probably won't need it but it's there if you do.
UpdateWarningState just hides/shows the warning label based on the validity of the inputs.
private void UpdateWarningState()
{
warningLabel.Visible = !IsInputValid(start.Value.TimeOfDay, lunch.Value.TimeOfDay, end.Value.TimeOfDay);
}
I had suggested in comments on the previous question that it seemed to make sense to get true if the inputs are valid and then use the logical negative for the visibility of the warning label.
As Paul Hebert pointed out, you really only need to compare a TimeSpan, so IsInputValid receives the TimeOfDay property to deal with only that much.
private bool IsInputValid(TimeSpan startTime, TimeSpan lunchTime, TimeSpan endTime)
{
return startTime < lunchTime && lunchTime.Add(TimeSpan.FromMinutes(30)) < endTime;
}
In fact, even though you're only inputting a time, the control still returns a date part in its Value property. If you want to be certain that you're not comparing times in different dates, you'll definitely need to use the TimeOfDay property. That said, by not presenting the date part, you have a measure of control over that so it's not a pressing concern. If you had to worry about crossing over midnight, that would complicate things.
Note that I've dealt with that earlier assumption that lunch is a fixed length by adding 30 minutes in the comparison to the end time.
Why not just do all that in the ValueChanged event handler?
The Single Responsibility Principle. IsInputValid does one thing: business logic; it tells you if the inputs are valid based on range testing. UpdateWarningState does a different thing: UI logic; it updates the visibility of warning label based on the validity of the inputs.
UpdateWarningState is reusable. You can call it from other event handlers in the future. Event handlers really shouldn't ever do much. They're more like telephone operators: "how may I direct your call?"
IsInputValid is reusable. The business logic can be extracted from your UI code at some point in the future and be reused by something else. I'll admit that the name leaves something to be desired; it fits here but probably should be different outside this context.
But what good is this user control if you have no way of working with its data? The consumer needs to be able to interact with it. A user control is just another class so you can define public properties, methods, and events as you see fit. We'll add properties for the three values of interest:
public TimeSpan Start
{
get => start.Value.TimeOfDay;
set => start.Value = start.Value.Date + value;
}
public TimeSpan Lunch
{
get => lunch.Value.TimeOfDay;
set => lunch.Value = lunch.Value.Date + value;
}
public TimeSpan End
{
get => end.Value.TimeOfDay;
set => end.Value = end.Value.Date + value;
}
What's interesting to note about these properties is that they don't have their own backing storage. Instead, they defer to the controls and translate between their own TimeSpan data type and the controls' DateTime data type. On get, they return just the TimeOfDay property. On set, they remove the time portion (with .Date) and add the time of day.
If you were building this for someone else to consume, you'd want to ensure that the Days property is 0 and that the whole value is non-negative, and either throw ArgumentOutOfRangeException or (gasp!) clamp the value to the acceptable range.
Now that you have a functioning control for a single day, you can slap a bunch of them on the main form. Back in Form1, add seven instances of the DayPanel control and name them monday through sunday. Before we get to initialization, let's create a lookup for these user controls.
private readonly Dictionary<DayOfWeek, DayPanel> _dayPanelLookup;
public Form1()
{
InitializeComponent();
_dayPanelLookup = new Dictionary<DayOfWeek, DayPanel>()
{
[DayOfWeek.Monday] = monday,
[DayOfWeek.Tuesday] = tuesday,
[DayOfWeek.Wednesday] = wednesday,
[DayOfWeek.Thursday] = thursday,
[DayOfWeek.Friday] = friday,
[DayOfWeek.Saturday] = saturday,
[DayOfWeek.Sunday] = sunday
};
}
Now the Load handler can then initialize all the properties. This DefaultTime duplicates the TimeSpan.Zero constant for the purpose of giving it a distinct meaning and can help with refactoring later on.
private static readonly TimeSpan DefaultTime = TimeSpan.Zero;
private void Form1_Load(object sender, EventArgs e)
{
SetDefaults();
}
private void SetDefaults()
{
foreach (DayPanel dayPanel in _dayPanelLookup.Values)
{
dayPanel.Start = DefaultTime;
dayPanel.Lunch = DefaultTime;
dayPanel.End = DefaultTime;
}
}
And just for fun, we can use _dayPanelLookup to grab one of them based on a variable containing the day of the week.
public void someButton_Click(object sender,
{
DayOfWeek whichDay = SelectADay();
DayPanel dayPanel = _dayPanelLookup[whichDay];
// ...
}
That should address the main concern of organizing the controls and making it easy to work with them and their values. What you do with it once the user presses some as-yet-unidentified button on the form is a whole new adventure.
There are yet better ways of doing all of this, I'm sure. I'm not a UI developer, I just play one on TV. For your purposes, I hope this not only gives you the guidance you needed at this point in this project but also illuminates new avenues of thought about how to structure your programs in the future.
It is unclear what you want the date component of the date part of DateTime to be DateTime.Parse("00:00") should return midnight today or 12/27/18 12:00:00 AM;
This is also the same value as DateTime.Today
In addition, you can create a new DateTime with a constructor
monStart.Value = new DateTime(2018, 12, 27, 0, 0, 0);
This is midnight the today
Note:
Reading the description in your updated question, it appears that the DateTimePicker controls values are accessed on a Button Click. If this is the actual scenario, you probably don't need a DateTime array field at all: you could just read the values directly from the DTP controls and use the values in-place.
The example assumes (to comply with the question) that you need that array anyway.
A possible way to proceed:
Set the default values in the Form.Load event. Initialize the monSchedule array values right after, so the values are synchronized. Note that the Form.Load event handler code is (of course) executed after the class constructor (public Form1() { }): the Form object must be already initialized.
Assign an event handler to all the DateTimePicker controls (same event for all). The event handler is used to assign the new values to the monSchedule array. The event could be the ValueChanged event or, possibly, the more generic Validating event. The former is raised each time you change any part of the Time value (the hour value or minutes value). The latter only when the control loses the focus. Your choice.
Use the sender object in the event handler to determine which control raised the event and update the corresponding array value.
An example, using a switch statement and a case statement with a when clause:
Notes:
1. You need C# 7.0+ to use this switch syntax. Otherwise, you could switch using a Type pattern (see the Docs) or the DateTimePicker name (see the example).
2. The DTP_ValueChanged(object sender, EventArgs e) event (the ValueChanged handler) is assigned to all the DateTimePicker controls.
public partial class Form1 : Form
{
DateTime[] monSchedule = new DateTime[3];
private void Form1_Load(object sender, EventArgs e)
{
SetDefaultDTPValues();
}
private void SetDefaultDTPValues()
{
monStart.Value = DateTime.Parse("00:00");
monEnd.Value = DateTime.Parse("00:00");
monLunch.Value = DateTime.Parse("00:00");
monSchedule[0] = monStart.Value;
monSchedule[1] = monEnd.Value;
monSchedule[2] = monLunch.Value;
}
private void DTP_ValueChanged(object sender, EventArgs e)
{
switch (sender)
{
case DateTimePicker dtp when dtp.Equals(monStart):
monSchedule[0] = dtp.Value;
break;
case DateTimePicker dtp when dtp.Equals(monEnd):
monSchedule[1] = dtp.Value;
break;
case DateTimePicker dtp when dtp.Equals(monLunch):
monSchedule[2] = dtp.Value;
break;
}
}
}
On a Button.Click event:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show($"Start: {monSchedule[0].ToString("hh:mm tt")} " +
$"End: {monSchedule[1].ToString("hh:mm tt")} " +
$"Lunch: {monSchedule[2].ToString("hh:mm tt")}");
}
If the C# version in use doesn't allow this switch statement syntax, you can use the DateTimePicker name instead (there are other options, see the examples in the Docs):
private void DTP_ValueChanged(object sender, EventArgs e)
{
DateTimePicker dtp = sender as DateTimePicker;
switch (dtp.Name)
{
case "monStart":
monSchedule[0] = dtp.Value;
break;
case "monEnd":
monSchedule[1] = dtp.Value;
break;
case "monLunch":
monSchedule[2] = dtp.Value;
break;
}
}

Proper way for datepickers validaton in c#? (windows forms)

Just can't get it with datepicker validation.
I have datepicker From and datepicker To, so I want to prevent the user from doing some kung fu and seting datepicker From to be bigger than datepicker To, I've bumped across some questions but couldn't find the answer, so I've tried doing the easiest way I could think of:
Set MaxDate property for datepicker from in form_load event
private void Form1_Load(object sender, EventArgs e)
{
datepickerFrom.MaxDate = datepickerFrom.Value;
}
Then do the same for value_changed event
private void datepickerFrom_ValueChanged(object sender, EventArgs e)
{
datepickerFrom.MaxDate = datepickerFrom.Value;
}
This was easy and fine, only few lines of code, and I've only needed datepickerFrom_ValueChanged event, but recently I've tried typing date into datepicker insted of selecting it, and then all hell broke loose.
So I came to some solution for validation, instead of setting MaxDate property, I've tried this.
private void dtFrom_ValueChanged(object sender, EventArgs e)
{
DateTime from = datepickerFrom.Value;
DateTime to = datepickerTo.Value;
int year= from.Year > to.Year ? to.Year : from.Year;
int month = from.Month > to.Month ? to.Month : from.Month;
int day = from.Day > to.Day ? to.Day : from.Day;
int hour = from.Hour > to.Hour ? to.Hour : from.Hour;
int minute = from.Minute > to.Minute ? to.Minute : from.Minute;
int second = from.Second > to.Second ? to.Second : from.Second;
//setting datepicker value
datepickerFrom.Value = new DateTime(year, month, day, hour, minute, second);
}
This works fine, but feels like bit of headache, and I have to do this for datepickerTO_ValueChanged event also, sure I could make one method and call it two times, but still feels like there is a batter way for this, so any suggestions?
Thank you for your time
Solution 1:
You can handle datePickerTo close event and do something like:
private void dateTimePickerTo_CloseUp(object sender, EventArgs e)
{
DateTime fromdate = Convert.ToDateTime(dateTimePickerFrom.Value);
DateTime todate1 = Convert.ToDateTime(dateTimePickerTo.Value);
if (fromdate > todate1)
//Error
}
You can also use DateTime.Compare whcih get two date
like
int result = DateTime.Compar(dateTimePickerFrom.Value ,dateTimePickerTo.Value);
if result is 1 means From date is earlier, see this link.
Note1:
but as you said if user type in From or To textboxes then closeup event never fire so you need compare them in where you want to process
such as button click.
Note2:
As #Sinatr comment if Value is DateTime then don't need to convert it so the code would be like:
if (dateTimePickerFrom.Value >dateTimePickerTo.Value)
//Error
Your proposal would lead to a horrible interface. Suppose the following case:
From = 1 jan 2000
To = 1 feb 2000
User wants to change both values to 2010. He starts with the from value:
From = 1 jan 2010
Now he wants to change the TO value to 1 feb 2010. Alas, he can't.
Proper usage would be: add some button with which the operator can affirm he has changed all data, start checking it and update. In windows this button is usually named Apply Now or OK. Why deviate from this windows standard.
private void OnFormLoading(object sender, ...)
{
this.FromDate.MinValue = ... // use the real absolute min value you want ever to allow
this.FromDate.MaxValue = ...;
this.ToDate.MinValue = ...;
this.ToDate.MaxValue = ...;
}
Don't do any checking as long as the operator is making changes. Strat checking the input values when he indicates that he finished making changes:
private void OnButtonApplyNow_Clicked(object sender, ...)
{
bool InputOk = CheckInput();
if (!inputOk)
{
ShowIncorrectInput(); // for instance using a MessageBox
}
}

Datatype for submit to database

I'm sending the contents of text boxes and checkboxes to my database via a WCF service.
So far, I have
fNameTxtBox.Text, - string
(DateTime) BirthDate.Value, - System.DateTime
toggle1.IsChecked, - bool
But what happens if the datatype is int?
Unfortunately the autocomplete does not help me as such, and of course it doesn't accept .Text as an ending.
Anybody able to lend a hand and let me know what this would be?
EDIT:
Here is my complete statement that I am trying to complete. I am looking for the ending for ownerTextBox which for which the method required it to be an int, when the source is a text box on a WP7 app:
private void addAccountBtn_Click(object sender, RoutedEventArgs e)
{
_ServiceClient.AddDriverAsync(fnameTxtBox.Text, snameTxtBox.Text, (DateTime)BirthDate.Value, phonemobNumBox.Text, toggle1.IsChecked, toggle2.IsChecked, toggle3.IsChecked, toggle4.IsChecked, toggle5.IsChecked, toggle6.IsChecked, toggle7.IsChecked, toggle8.IsChecked, toggle9.IsChecked, toggle10.IsChecked, toggle11.IsChecked, toggle12.IsChecked, toggle13.IsChecked, toggle14.IsChecked, toggle15.IsChecked, ownerTextBox.????);
}
ie replace the ???? with the correct ending, or reformat that part as such so that it works.
You need to perform validation on the client to ensure that an invalid value never gets sent to your service. You can do this by checking if the value is a integer, and display a message if its not. Only send the data to your service if it meets the validation criteria.
public void OnButtonClick(object sender, EventArgs e) {
int value;
bool isValid = int.TryParse(textBox.Text, out value);
if (isValid) {
// send to WCF
}
else {
// display a message
}
}
You will need to parse the value using the int class, e.g.
int.Parse(myTextBox.Text)
Note that int.Parse will throw an exception if the value cannot be represented as an integer, so you may want to perform appropriate validation or exception handling. Look into the TryParse family of methods.
You may find it useful to read up on Casting, Type Conversion, and Parsing.
Using the source-code you posted, you would change it to:
private void addAccountBtn_Click(object sender, RoutedEventArgs e)
{
_ServiceClient.AddDriverAsync(
fnameTxtBox.Text, <snip_lots_of_arguments>,
toggle15.IsChecked,
int.Parse(ownerTextBox.Text)); //I've only changed the very last bit here
}

How to create a textbox that has decimal value

I need to add a textbox in my application that starts showing with the value 0.00 just like a ATM, as you type the numbers then it keeps the two decimal point until satisfied with the value for example the sequence to end up of a value of 1023.00 would be (as I type)
0.01
0.10
1.02
10.23
102.30
1023.00
Is this possible to do in a windows forms application?. I am just not sure how to go about it.
Thank you.
In this kind of scenario I would not use a textbox, but a label or a read-only textbox. To get the user input just use the key-press event on your form (you have to enable KeyPreview on the form too) - then just remember the keys/numbers pressed and output the format you are targeting - should be a rather easy algorithm (Char.IsNumber, and String.Format might come in handy):
private int _inputNumber = 0;
private void Form_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (!Char.IsNumber(e.KeyChar)) return;
_inputNumber = 10*_inputNumber + Int32.Parse(e.KeyChar.ToString());
ReformatOutput();
}
private void ReformatOutput()
{
myOutput.Text = String.Format("{0:0.00}", (double)_inputNumber / 100.0);
}
Note: Why not use a textbox - because it's internal logic with select/replace/remove/type is so overcomplicated that the cases you would have to check are just to much to handle gracefully - so instead of trying to change a cannon into a sling you should start with the sling.

Winforms DateTimePicker set default text and/or value

I have a DateTimePicker with ShowCheckBox = true on my winforms app. If I do this in the forms constructor:
DateFrom.Checked = true;
DateFrom.Value = DateTime.Today.AddDays(-7);
Then set DateFrom.Checked = false; in the FormShown event, it does what I would like, the text in the control defaults to 7 days before today, and the checkbox is unchecked.
If I try to only set the Value, the text stays as today. If I reset Checked = false anytime before the FormShown event, the text stays as today.
Now I've moved this code to a user control, so to use the same "hack" will require even more hacking, so at this point I'm hoping someone has an easier method. Maybe just another property I can set besides from Value that actually works? :)
I tried this also:
DateFrom.Text = DateTime.Today.ToString(DateFrom.CustomFormat);
Instead of setting the value, or in addition to it, to no avail.
Typical, I tried for hours before posting my question, then right after I thought it might somehow be related to the creation of the window handle. So I came up with this solution. Will still be happy to have something better, but this doesn't seem to bad if I have to stay with this:
DateFrom.Checked = true;
DateFrom.Value = DateTime.Today.AddDays(-7);
if (DateFrom.Handle == null)
System.Threading.Thread.Sleep(0);
DateFrom.Checked = false;
Checking Handle forces the window handle to be created, so then I'm able to uncheck the control without it defaulting to today's date for the text when the window handle is created later. I just use Sleep(0) as a trick to make sure the compiler doesn't optimize the code and compile it out all together (not sure if that would even happen, but like to be sure, and condition shouldn't always be false so should never Sleep(0) anyway).
It might also be that the control is simply not redrawing properly, particularly if you have it as a usercontrol. You might try calling Invalidate() on the control after setting the Value to see if that's the problem.
I changed your self answer and made it like this:
public ProcessFailureForm()
{
InitializeComponent();
//Blah blah blah
dtFrom.HandleCreated += delegate //if you need sender or EventArgs use: delegate(object sender, EventArgs e)
{
dtFrom.Checked = true;
dtFrom.Value = DateTime.Today.AddDays(-7);
dtFrom.Checked = false;
};
}
Update:
Actually first i think like you, but after doing this, i tried and find out that the Checked state won't affect the process... so it can be reduced to:
public ProcessFailureForm()
{
InitializeComponent();
//Blah blah blah
dtFrom.HandleCreated += delegate //if you need sender or EventArgs use: delegate(object sender, EventArgs e)
{
dtFrom.Value = DateTime.Today.AddDays(-7);
};
}

Categories

Resources