This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credits: http://stackoverflow.com/questions/2683442/where-can-i-find-the-clamp-function-in-net | |
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T> | |
{ | |
if (val.CompareTo(min) < 0) return min; | |
else if(val.CompareTo(max) > 0) return max; | |
else return val; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class Program | |
{ | |
[DllImport("user32.dll")] | |
private static extern bool SetForegroundWindow(IntPtr hWnd); | |
/// <summary> | |
/// The main entry point for the application. | |
/// </summary> | |
[STAThread] | |
static void Main(string[] args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DllImport("user32")] | |
private static extern bool ShowScrollBar(IntPtr hwnd, int wBar, bool bShow); | |
void HideHorizontalScrollBar(ListView lv) | |
{ | |
ShowScrollBar(lv.Handle, 0, false); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Reflection; | |
namespace System | |
{ | |
internal static class ObjectExtensions | |
{ | |
public static PropertyInfo GetPropertyInfo(this Type type, string name) | |
{ | |
string[] bits = name.Split('.'); | |
for (int i = 0; i < bits.Length - 1; i++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inspired by http://stackoverflow.com/q/301809/24472 | |
public static string Property<TProp>(Expression<Func<T, TProp>> expression) | |
{ | |
var s = expression.Body.ToString(); | |
var p = s.Remove(0, s.IndexOf('.') + 1); | |
return p; | |
} | |
// Example: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTime truncateMs(DateTime date) | |
{ | |
return new DateTime((date.Ticks / TimeSpan.TicksPerSecond) * TimeSpan.TicksPerSecond); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static T Max<T>(T x, T y) | |
{ | |
return (Comparer<T>.Default.Compare(x, y) > 0) ? x : y; | |
} | |
static T Min<T>(T x, T y) | |
{ | |
return (Comparer<T>.Default.Compare(x, y) > 0) ? y : x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static string GetEnvironment(string environmentVariableName, string defaultValue) | |
{ | |
var Parameter = Environment.GetEnvironmentVariable(environmentVariableName, EnvironmentVariableTarget.Machine); | |
if (!string.IsNullOrEmpty(Parameter)) | |
return Parameter; | |
Environment.SetEnvironmentVariable(environmentVariableName, defaultValue, EnvironmentVariableTarget.Machine); | |
return defaultValue; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int GetDataGridViewHeight(DataGridView dataGridView) | |
{ | |
var sum = dataGridView.ColumnHeadersVisible ? dataGridView.ColumnHeadersHeight : 0 + | |
dataGridView.Rows.OfType<DataGridViewRow>().Where(r => r.Visible).Sum(r => r.Height); | |
return sum; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage : | |
textBoxChangedEventMask = new EventMask( | |
() => { textBox1.TextChanged += new EventHandler(textBox1_TextChanged); }, | |
() => { textBox1.TextChanged -= new EventHandler(textBox1_TextChanged); } | |
); | |
//in the event code: | |
try | |
{ |