Category: "Example Codes"
Just a quick for time format
That is common to have "AM/PM" in time format. That is usng "tt"
Example:
Code
DateTime.Now.ToString("hh:mm tt") |
Sub-window should not show in the task bar
That is a common mistake for myself. I like to create some sub-windows which are acting a dialog. I am so easy to forget set ShowInTaskbar = false.
Bolded the dates in MonthCalendar
I am writing a simple diary application. I am using a monthcalendar control to select the date to load the diary. I need the control to display the date in bolded if that date on the calendar has the data. That is easy and simple. Just using BoldedDates.
Code
List<DateTime> boldedDates = new List<DateTime>(); | |
foreach(DateTime boldedDate in entries.Keys) | |
{ | |
boldedDates.Add(boldedDate); | |
} | |
this.monthCalendar1.BoldedDates = boldedDates.ToArray(); |
Get the current assembly version
That is very easy by using Reflection.
Code
using System.Reflection; | |
Assembly.GetExecutingAssembly().GetName().Version; |
Regular Expression Validation
I like to use regular expression validation. That is simple.
You only need to use:
Code
using System.Text.RegularExpressions |
For the numeric value validation:
Code
Regex regex = new Regex(@"^[0-9]*$"); | |
if (!regex.IsMatch(textBox1.Text)) | |
{ | |
MessageBox.Show("Invalid value, integer only!"); | |
} |