DEV Community

Kiron Roy
Kiron Roy

Posted on • Updated on

C# WinForm Tutorials

Object Oriented Programming

These Winform tutorials assume an understanding of Object Oriented Programming, particularly: events, interfaces and inheritances, as well the basics of the C# programing language.

However, the tutorials can still be completed with patience. Note, I completed the tutorials with Visual Studio 2019, even though some of the tutorials were made a few years ago.

WinForm Basics

  • WinForms are event-driven desktop applications written in C#.
  • There is a visual design mode where a developer can drop buttons, menus, and labels. These dropped items, or specifically objects are instances of their respected classes.
    • WinForms are split into Partial classes.
    • There is a "code-behind" everything that is dropped into the form. This file reflects the visual look of the application, font-family, colors, size, etc. The form itself is a instance of the Form class
    • Then there is a code file (with the logic). Here is an example from the Crossword tutorial:
// Crossword (which is a form) inherits from the Form Class   
public partial class CrossWord : Form  
        Clues clueWindow = new Clues();
        List<IdCells> idCells = new List<IdCells>();
        public string puzzleFile = Application.StartupPath + @"\Puzzles\puzzle.pzl";

        public CrossWord()
       // InitializeComponent() method is automatically 
       // created and managed by Windows Forms designer 
       // and it defines everything you see on the form.

Enter fullscreen mode Exit fullscreen mode
  • WinForms two partial classes are implemented to separate design from logic.
  • Clicking, buttons text boxes creates events and that code goes to another file (Crossword code example above).
  • During build process the compiler merges the two classes together.

Here are the four examples of WinForm tutorials:

One thing to note in C#
vairable names are always in camelCase: int myNumber
where Method names are written in PascalCase private void MyMethod().

Rename all your vairables by pressing Ctrl + RR and retype a name, this will make the change everywhere in the program.

Discussion (0)