Skip to content

Instantly share code, notes, and snippets.

View sachintha81's full-sized avatar

Sach sachintha81

View GitHub Profile
@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 / AllCombinations.cs
Created January 13, 2017 21:18
All Possible Combinations of a list of Values
namespace Combinations
{
public class Combinations
{
public static void Main(string[] args)
{
GetCombination(new List<int> { 1, 2, 3 });
}
public static void GetCombination(List<int> list)
@sachintha81
sachintha81 / MaskTextbox.cs
Created January 13, 2017 21:16
WPF TextBox Input Restrictions
/// <summary>
/// Provides masking behavior for any TextBox
/// </summary>
public static class Masking
{
private static readonly DependencyPropertyKey _maskExpressionPropertyKey = DependencyProperty.RegisterAttachedReadOnly(""MaskExpression"",
typeof(Regex),
typeof(Masking),
new FrameworkPropertyMetadata());
@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 / ValidateXMLUsingSchema.cs
Created January 13, 2017 21:08
C# Validating XML using Schemas
using System;
using System.IO;
using System.Xml.Linq;
using System.Xml.Schema;
namespace XmlValidation
{
class Program
{
static void Main(string[] args)
@sachintha81
sachintha81 / ExtractSubstring.cs
Created January 13, 2017 21:07
WPF + C# Extract a Substring from a String between two specified Parts
using System;
using System.Collections.Generic;
using System.Windows;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Input;
using System.Xml.Linq;
namespace StringProgram
@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 / 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;