Skip to content

Instantly share code, notes, and snippets.

View MatthewKing's full-sized avatar

Matthew King MatthewKing

View GitHub Profile
@MatthewKing
MatthewKing / ListViewWithoutFocus.cs
Last active August 29, 2015 13:56
ListViewWithoutFocus.cs
// Copyright Matthew King 2014.
// Licensed under the Boost Software License, Version 1.0.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
/// <summary>
/// Extends the System.Windows.Forms.ListView class, removing the focus indicators.
/// </summary>
@MatthewKing
MatthewKing / gist:9657697
Created March 20, 2014 05:16
Double-buffering in WinForms using WS_EX_COMPOSITED
/// <summary>
/// A System.Windows.Forms.CreateParams that contains the required creation parameters
/// when the handle to the control is created.
/// </summary>
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
@MatthewKing
MatthewKing / GeoCoordinateWatcherFixed.cs
Last active August 29, 2015 13:58
Fixes the dodgy miswired events in Microsoft's base GeoCoordinateWatcher implementation.
using System;
using System.Device.Location;
/// <summary>
/// Supplies location data that is based on latitude and longitude coordinates.
/// </summary>
/// <remarks>
/// Fixes the dodgy miswired events in Microsoft's base GeoCoordinateWatcher implementation.
/// </remarks>
class GeoCoordinateWatcherFixed : GeoCoordinateWatcher, IGeoPositionWatcher<GeoCoordinate>
@MatthewKing
MatthewKing / Get-ApplicationReference.ps1
Last active August 29, 2015 14:03
Get a ClickOnce Application Reference from a ClickOnce Application Deployment Manifest.
function Get-ApplicationReference([string] $deploymentManifestPath) {
[xml]$content = Get-Content $deploymentManifestPath
$identity = $content.assembly.assemblyIdentity
$codebase = $content.assembly.deployment.deploymentProvider.codebase
$appref = '{0}#{1}, Culture={2}, PublicKeyToken={3}, processorArchitecture={4}' -f $codebase, $identity.name, 'neutral', $identity.publicKeyToken, $identity.processorArchitecture
return $appref
}
@MatthewKing
MatthewKing / FormExtensions.cs
Last active August 29, 2015 14:13
Extension methods adding an awaitable ShowAsync method to System.Windows.Forms.Form.
using System;
using System.Threading.Tasks;
using System.Windows.Forms;
/// <summary>
/// Extension methods for System.Windows.Forms.Form.
/// </summary>
static class FormExtensions
{
/// <summary>
// Adapted from Greg Beech's blog post:
// http://gregbee.ch/blog/natural-sort-order-of-strings-and-file
// Distributed under the Creative Commons Zero (CC0) license.
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Security;
/// <summary>
/// A string comparer that uses the StrCmpLogicalW function for natural string comparisons.
@MatthewKing
MatthewKing / TypeExtensions.cs
Created July 22, 2012 12:49
Extension method to get a user-friendly string representation of a specified Type's name.
// Copyright Matthew King 2012.
// Boost Software License - Version 1.0 - August 17th, 2003
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
@MatthewKing
MatthewKing / EquatableTemplate.cs
Created July 23, 2012 08:40
Template implementation of IEquatable.
/// <summary>
/// Determines whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// true if the current object is equal to the specified object; otherwise, false.
/// </returns>
public bool Equals(T other)
{
if (Object.ReferenceEquals(other, null)) return false;
@MatthewKing
MatthewKing / ListViewHelper.cs
Created November 16, 2012 06:22
Provides methods to (properly) enable and disable double buffering on a ListView control.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
/// <summary>
/// Provides methods to (properly) enable and disable double buffering on a ListView control.
/// Based on Giovanni Montrone's article on CodeProject at
/// <see cref="http://www.codeproject.com/KB/list/listviewxp.aspx"/>,
/// and on the StackOverflow answer at
/// <see cref="http://stackoverflow.com/a/162770/286936"/>.
// Copyright Matthew King 2011-2013.
// Distributed under the Boost Software License, Version 1.0.
// (See http://www.boost.org/LICENSE_1_0.txt)
using System;
using System.Globalization;
using System.Linq.Expressions;
using System.Reflection;
/// <summary>