2006-02-26

Screen Capture 2

Screenshot of 'Screen Capture 2' I've written a new version of my screen capture tool, from scratch. You can download it from the sandbox at Channel 9.

2006-02-18

Screen capture tool

Screenshot of 'Screen Capture' I've written a little screen capture tool, for fun. You can download it from the sandbox at Channel 9. I did not include the source code, because there isn't a lot of it. Just use Reflector for that. Here's the bit of code that does the actual capturing and copying to the clipboard:
Rectangle region = ...; // the screen region to capture
using (Bitmap bitmap =
    new Bitmap(region.Width, region.Height, PixelFormat.Format32bppArgb))
using (Graphics bitmapGraphics = Graphics.FromImage(bitmap))
{
    bitmapGraphics.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size);
    Clipboard.SetImage(bitmap);
}
EDIT: I've updated the tool: after capturing, you can now directly save the screenshot too.

2006-02-17

Years, months and days between 2 dates

Here you can find a method that can calculate the years, months and days between 2 dates.
/// <summary>Calculates the difference between 2 dates in years, months and days.</summary> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <param name="years">The variable that will contain the years.</param> /// <param name="months">The variable that will contain the months.</param> /// <param name="days">The variable that will contain the days.</param>
public static void DateDifference(DateTime startDate, DateTime endDate, out int years, out int months, out int days) { years = endDate.Year - startDate.Year; months = endDate.Month - startDate.Month; days = endDate.Day - startDate.Day; if (days < 0) months -= 1; while (months < 0) { months += 12; years -= 1; } TimeSpan timeSpan = endDate - startDate.AddYears(years).AddMonths(months); days = (int)Math.Round(timeSpan.TotalDays); }
And here is a method that uses the previous method and returns a string representation of the difference:
/// <summary>Calculates the difference between 2 dates, and returns it as a formatted string.</summary> /// <param name="startDate">The start date.</param> /// <param name="endDate">The end date.</param> /// <returns>The formatted string that represents the calculated difference.</returns>
public static string DateDifference(DateTime startDate, DateTime endDate) { int years, months, days; DateDifference(startDate, endDate, out years, out months, out days); return ((years != 0 ? years.ToString() + "y " : "") + (months != 0 ? months.ToString() + "m " : "") + (days != 0 ? days.ToString() + "d" : "")).TrimEnd(); }
Tags: .

2006-02-02

Great interview with Anders Hejlsberg

I just watched this excellent interview with Anders Hejlsberg at Channel 9. Anders Hejlsberg talks about his life, his past and present work and his passion. Very inspiring stuff from a fascinating man.