Skip to content

Instantly share code, notes, and snippets.

View sachintha81's full-sized avatar

Sach sachintha81

View GitHub Profile
@sachintha81
sachintha81 / ExtendedDisplay.cpp
Last active November 30, 2023 20:06
Set Display Settings to EXTEND mode in Windows 7 using C++
public void main(int argc, char const *argv[])
{
// To identify the current configuration:
UINT32 PathArraySize = 0;
UINT32 ModeArraySize = 0;
DISPLAYCONFIG_PATH_INFO* PathArray;
DISPLAYCONFIG_MODE_INFO* ModeArray;
DISPLAYCONFIG_TOPOLOGY_ID CurrentTopology;
@sachintha81
sachintha81 / ReadInto2DArray.c
Created January 13, 2017 21:11
Reading a Text File into a 2D Array in C
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
// Allocate memory for the array like this:
int** array;
array = malloc(n * sizeof(*array)); /* Assuming `n` is the number of rows */
@sachintha81
sachintha81 / MainWindow.xaml.cs
Last active March 6, 2023 20:31
WPF Progress Bar in a separate Window
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows;
namespace WPFProgressBar
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
@sachintha81
sachintha81 / WPFMessengerClass.cs
Created January 13, 2017 21:23
Messenger Class for the WPF + MVVM Pattern
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MVVMMessenger
{
public class Messenger
@sachintha81
sachintha81 / CustomControl.cs
Last active October 21, 2021 02:16
Drawing a Custom Control on C# WinForms
using System;
using System.Drawing;
using System.Windows.Forms;
namespace CustomControls
{
public class NodeControl : Control
{
private Graphics G = null;
@sachintha81
sachintha81 / DynamicallySetDGRows.cs
Created January 13, 2017 21:21
WPF Dynamically Setting number of Rows/Columns in a Grid Control
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace PrisonersDilemma.Utility
{
/// <summary>
/// Taken from: https://rachel53461.wordpress.com/2011/09/17/wpf-grids-rowcolumn-count-properties/
/// </summary>
public class GridHelpers
@sachintha81
sachintha81 / ColorCodeDGV.xaml
Last active December 18, 2019 06:47
WPF + C# : Display Data and Color Code a DataGrid using Binding
<Window x:Class="ColorLibrary.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ColorLibrary"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="MainWindow" Height="500" Width="400">
<Window.Resources>
@sachintha81
sachintha81 / LoopEnum.cs
Last active December 6, 2019 06:27
Loop through Enum
// Typed version
var values = Enum.GetValues(typeof(Foos)).Cast<Foos>();
// Helper function
public static class EnumUtil {
public static IEnumerable<T> GetValues<T>() {
return Enum.GetValues(typeof(T)).Cast<T>();
}
}
@sachintha81
sachintha81 / EqualityComparer.cs
Created August 9, 2017 22:45
Equality Comparer for comparing objects based on members
using System;
using System.Collections.Generic;
using System.Linq;
// SO Link 1 : https://stackoverflow.com/a/263416/302248
// SO Link 2 : https://stackoverflow.com/q/45601078/302248
namespace ComparerGetHashCode
{
public class NumberClass
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackOverflow
{
class Program
{