Skip to content

Instantly share code, notes, and snippets.

View felipeabajo's full-sized avatar

@felipeabajo felipeabajo

View GitHub Profile
@felipeabajo
felipeabajo / exiting-winforms-applications
Created November 14, 2023 15:39
Snippets for exiting WinForms applications
this.Close(); //If called in the main form, it closes the app too.
Application.Exit();
System.Diagnostics.Process.GetCurrentProcess().Kill(); // Causes an abnormal process termination and should only used when necessary.
@felipeabajo
felipeabajo / files-in-csharp
Created November 14, 2023 15:30
Snippets for working with files in C#
/*OPERATIONS WITH FILES*/
/*Check if file exists*/
private Boolean ExistsFile(string filePath)
{
if (File.Exists(filePath)) return true;
else return false;
}
@felipeabajo
felipeabajo / paths-in-csharp
Last active November 14, 2023 14:32
Snippets for working with paths in C#
/*PATHS*/
/*Special folders*/
string FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments); //C:\Users\Public\Documents in Windows
/*GENERATION OF PATHS*/
/*Paths of documents*/
string FilePath = System.IO.Path.Combine(folderName, fileName);
string FilePath = System.IO.Path.Combine(destinationFolderPath, selectedWord + " - " + selectedTypeOfProject + ".pdf");
@felipeabajo
felipeabajo / typography-in-csharp
Created November 14, 2023 13:32
Snippets for working with typography in C#
/*FONT CUSTOMIZATION*/
/*Size*/
private Font SetFontSize(int fontSize)
{
Font newFont;
try
{
newFont = new Font(FontFamily.GenericSansSerif, fontSize);
}
catch (Exception ex)
@felipeabajo
felipeabajo / documents-in-csharp
Last active November 14, 2023 17:00
Snippets for working with documents in C#
/*TEMPLATES FOR WORKING WITH DOCUMENTS*/
/*Word*/
private void TemplateUsageWordDocument(string filePath)
{ //Open app and document
Word.Application WordApp= new Word.Application();
Word.Document wordDoc = WordApp.Documents.Open(filePath, ReadOnly: true, Visible: false);
//Include operations here
//Close document and app
@felipeabajo
felipeabajo / folders-in-csharp
Last active November 14, 2023 14:51
Snippets for working with folders in C#
/*OPERATIONS WITH FOLDERS*/
/*Check if folder exists*/
private Boolean ExistsFolder(string folderPath)
{
if (Directory.Exists(folderPath)) return true;
else return false;
}
/*Create folder*/
private void CreateFolder(string folderPath)