Move a form that doesn't have a titlebar

Here's how to move a form that doesn't have a titlebar:

using System;

using System.Runtime.InteropServices; using System.Windows.Forms;

namespace MoveFormWithoutTitlebar { public partial class Form1 : Form {

    public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;

    public static extern int SendMessage(IntPtr hWnd,
                     int Msg, int wParam, int lParam);

    public static extern bool ReleaseCapture();

    public Form1() {

    private void Form1_MouseDown(object sender, MouseEventArgs e) {
        if (e.Button == MouseButtons.Left) {
            SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);


Create an About form

How to programmatically create an About form and have it appear centered in a 1000x700 pixel MainForm:

            about = new Form();
        about.MaximizeBox = false;
        about.FormBorderStyle = FormBorderStyle.None;
        about.Size = new Size(400,300);
        about.TopMost = true;           

        Label lblAbout = new Label();
        lblAbout.Text = "About";
        lblAbout.Font = new Font("Verdana",14);
        lblAbout.AutoSize = true;
        int lblAboutLeft = (about.Width - lblAbout.Width)/2;            
        lblAbout.Left = about.Left + lblAboutLeft + 9;

        Button btnClose = new Button();
        btnClose.Text = "&Close";           
        btnClose.Width = 50;
        btnClose.Location = new Point(btnClose.Left + 347, btnClose.Top + 275);

        PictureBox picProgrammer = new PictureBox();
        picProgrammer.AutoSize = true;          
        picProgrammer.Image = Image.FromFile(".\\Resources\\Images\\bryanCircle.PNG");
        picProgrammer.Left += 2;
        picProgrammer.Top += 2;

        TextBox tb = new TextBox();
        tb.Font = new Font("Verdana",10);
        tb.Multiline = true;
        tb.ScrollBars = ScrollBars.Vertical;
        tb.Height = about.Height - lblAbout.Height - btnClose.Height  - 7;
        tb.Width = about.Width - picProgrammer.Width - 8;
        tb.Top = lblAbout.Top + lblAbout.Height + 2;
        tb.Left = picProgrammer.Left + picProgrammer.Width;
        string readData = File.ReadAllText(".\\Resources\\Texts\\about.txt");
        tb.Text = readData;

        int left = (this.Width - about.Width)/2;
        left += iMainFormLeft;
        int top = (this.Height - about.Height)/2;
        top += iMainFormTop;
        about.Location = new Point(left, top);

        btnClose.Click += new EventHandler(btnClose_Click);

My preferred FormLoad()

        void MainFormLoad(object sender, EventArgs e)
        blnShowingAbout = false;
        this.DoubleBuffered = true;
        this.Size = new Size(1000,700);
        this.FormBorderStyle = FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.Text = "\"Proofy\", the Proofreader's App — Wm. Miller Services ©2017";


Fade C# Form Gradually

        void showClosingMsgInTitlebarThenExit()
        this.Text = "Now closing the \"Proofy\" app...";
        for(Double d = 1.00; d > 0.00; d -= 0.025)
            this.Opacity = d;


upload file to server using C#

The following code sample shows uploading of text file "test.txt" in the app's directory to "" using login info and password "shitstorm":

namespace UploadExample {

class Program {

    static void Main(string[] args) {

        // Get the object used to communicate with the server.
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("");
        request.Method = WebRequestMethods.Ftp.UploadFile;

        request.Credentials = new NetworkCredential("", "shitstorm");

        // Copy the contents of the file to the request stream.
        StreamReader sourceStream = new StreamReader("test.txt");
        byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);

        FtpWebResponse response = (FtpWebResponse)request.GetResponse();

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);


        Console.WriteLine("Press a key to end program...");



Subordinate your cellphone

I often sit and think back to how life was when I were growing up. In a kind of nostalgic way my mind drifts into the past where notifications were not a part of my life. Where people wrote letters to one another, where every single conversation mattered, and where my home phone was the only way to truly contact me. My mind drifts and I’m back in the 2000’s, and think about how gradually the need to be contacted overshadowed my life. So much so, that the only time my phone is ever switched off is when the battery dies (and we all know the panic to find the nearest working, correct fitting charger). Shocking when I came to this realisation. I paused, and considered if my privacy even existed. Or if my time really belonged to me when anyone can invade my space at any time they so choose and call or text me. And then I got so tired of being everything to all people at anytime, and switched my phone off. This wasn’t great at first because it wasn’t comfortable. Change is often uncomfortable, especially when you realise that you cannot use your apps just because you’re avoiding being disturbed. It was then I discovered ‘Airplane Mode’

My life changed. I set boundaries. People soon knew that they cannot call or text me after 5pm because I’ll be in the air. It mean’t so much for me and the great thing was I could still use my phone as I so chose to.

I choose when to respond I am the CEO of my time I protect my peace I am not distracted during my quality time with my family I didn’t feel like my phone was a huge part of my life again Now while I couldn’t exactly emulate my past nostalgia, I did learn a few things about phones. We make them so much more valuable than we need to. We are less productive the more we are on them. We cannot give people our undivided attention when our relationship with our inbox is more of a time investment than the important people in our lives. I learned the art of control, and my original discomfort turned into power. Knowing fully well that I own my phone and that it doesn’t own me changed the way that I communicated with everyone. My phone turned into a phone and not a lifeline, I became more focused on what is most important, and I didn’t care for the red notification bubbles and instant nature of communication as I once did. I became a 9–5 person in my private life and this means that I no longer overcommit, over work and over stress about responding. Those who matter will wait, those who don’t want to wait do not value your time.

Image courtesy of Pixabay The final point on Airplane Mode is… your battery charges faster when it’s activated. Gotta love it.

Try it sometime. Fly.

This is not how your story ends.

Capturing standard output from console app

Here's code that redirects output from my Proofreading Tracker console app:

using System;
using System.Diagnostics;

sealed class TestRedirStdOutput
    public static void Main()
        Process p = new Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.Arguments = "titles";
        p.StartInfo.FileName = "prt.exe";

        // To avoid deadlocks, always read the output stream first and then wait.
        string output = p.StandardOutput.ReadToEnd();

        Console.WriteLine(" Captured this output:\n");
        Console.WriteLine(output + "\n");
        Console.WriteLine(" Press any key to exit...");