Skip to content

Instantly share code, notes, and snippets.

emoacht / BooleanToIntConverter.cs
Created Jun 3, 2021
Converter to change Grid.Column or Grid.Row utilizing FallbackValue (default value) and ConverterParameter (changed value)
View BooleanToIntConverter.cs
public class BooleanToIntConverter : IValueConverter
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
return ((value is true) && int.TryParse(parameter?.ToString(), out int buffer))
? buffer
: DependencyProperty.UnsetValue;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
emoacht / DisplayHelper.cs
Created May 28, 2021
Find index number of display shown in the OS's display settings. The reliability of this method is unknown.
View DisplayHelper.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
public static class DisplayHelper
#region Win32
emoacht / FontGlyphImage.cs
Created May 11, 2021
Get font glyph image from Segoe MDL2 Assets
View FontGlyphImage.cs
using System;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
/// <summary>
/// Font glyph image from Segoe MDL2 Assets
/// </summary>
public static class FontGlyphImage
emoacht /
Created May 8, 2021
Samples of emoji

🍱 bento

🔪 hocho

🍜 ramen

🍢 oden

🍡 dango

emoacht / TextReader.cs
Created May 3, 2021
Read text file with progress reporting
View TextReader.cs
using System.Threading.Tasks;
public class TextReader
public double Percentage { get; set; }
public async Task ReadAsync(string filePath)
var progress = new Progress<(double current, double total)>();
progress.ProgressChanged += (_, e) => Percentage = e.current /;
View DeviceDetectService.cs
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.ServiceProcess;
public partial class DeviceDetectService : ServiceBase
public DeviceDetectService()
emoacht / CustomContextMenuStrip.cs
Created May 1, 2021
ContextMenuStrip without the color gradation in image margin
View CustomContextMenuStrip.cs
using System.Drawing;
using System.Windows.Forms;
public class CustomContextMenuStrip
private class CustomColorTable : ProfessionalColorTable
public override Color ImageMarginGradientBegin => Color.Transparent;
public override Color ImageMarginGradientMiddle => Color.Transparent;
public override Color ImageMarginGradientEnd => Color.Transparent;
emoacht / ScreenHelper.cs
Created Mar 19, 2021
Get screen Rect from a FrameworkElement
View ScreenHelper.cs
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;
public static class ScreenHelper
public static Rect ToScreenRect(this FrameworkElement element) => GetMonitorRect(GetElementRect(element));
private static Rect GetElementRect(FrameworkElement element)
emoacht / TaskbarHelper.cs
Last active Feb 24, 2021
Enumerate sets of information on taskbar especially Device Instance ID and taskbar alignment.
View TaskbarHelper.cs
public enum TaskbarAlignment { Unknown, Left, Top, Right, Bottom }
public static class TaskbarHelper
#region Win32
[DllImport("User32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(
IntPtr hwndParent,
IntPtr hwndChildAfter,
emoacht / MonitorInformation.cs
Created Feb 20, 2021
Get taskbar placement from MONITORINFOEX.
View MonitorInformation.cs
public enum TaskbarPlacement { Unknown, Left, Top, Right, Bottom }
private TaskbarPlacement GetPlacement(MONITORINFOEX monitorInfo)
var m = monitorInfo.rcMonitor;
var w = monitorInfo.rcWork;
return (left: (m.left == w.left),
top: ( ==,
right: (m.right == w.right),