Skip to content

Instantly share code, notes, and snippets.

View AnshulKuthiala's full-sized avatar

AnshulKuthiala

View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AnshulKuthiala
AnshulKuthiala / Password.cs
Created December 24, 2018 10:16
[Console App Password Entry]
public static string GetPassword()
{
string password = "";
do
{
ConsoleKeyInfo key = Console.ReadKey(true);
// Backspace Should Not Work
if (key.Key != ConsoleKey.Backspace && key.Key != ConsoleKey.Enter)
{
password += key.KeyChar;
@AnshulKuthiala
AnshulKuthiala / SuggestTextBox.cs
Last active December 23, 2018 10:50
[SuggestTextBox]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Linq.Expressions;
using System.Windows.Forms;
public class SuggestTextBox : TextBox
{
#region fields and properties
@AnshulKuthiala
AnshulKuthiala / RemoveCustomization.cs
Last active December 21, 2018 14:37
[Remove Customization] #ExcelHelper Remove document customization from document
//Add reference to using Microsoft.VisualStudio.Tools.Applications.ServerDocument
using Microsoft.VisualStudio.Tools.Applications;
private static void RemoveCustomiation(string filePath, int attempt)
{
int maxAttempt = 10;
try
{
ServerDocument.RemoveCustomization(filePath);
@AnshulKuthiala
AnshulKuthiala / TLS.cs
Created December 14, 2018 15:00
[Enable TLS 1.2]
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
@AnshulKuthiala
AnshulKuthiala / Version.cs
Last active December 13, 2018 16:04
[Version Info] #ExcelHelper Set version info on the button label
using System.Deployment.Application;
private void RibbonCapitalGains_Load(object sender, RibbonUIEventArgs e)
{
if (ApplicationDeployment.IsNetworkDeployed)
{
var version = ApplicationDeployment.CurrentDeployment.CurrentVersion;
buttonAbout.Label = $"v{version.ToString(3)}";
}
}
@AnshulKuthiala
AnshulKuthiala / MoveForm.cs
Created December 10, 2018 18:28
[Move Form] Ability to move form using any component. Useful when form does not have a border.
private bool MouseDown { get; set; }
private System.Drawing.Point LastLocation { get; set; }
private void labelGetId_MouseDown(object sender, MouseEventArgs e)
{
MouseDown = true;
LastLocation = e.Location;
}
private void labelGetId_MouseMove(object sender, MouseEventArgs e)
@AnshulKuthiala
AnshulKuthiala / ShowExceptionMessage.cs
Created December 7, 2018 08:22
[Show Exception Message]
public static void ShowExceptionMessage(Exception exception)
{
MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}