You are on page 1of 10

Fundamental Network

Programming
Introduction to C# .NET, Window form and IO

Lecturer: MSc. Dang Le Bao Chuong Spring 2022


Agenda

I. C# Programming language
• Basic syntax, data structure

II. Window form


• How to create a Window form project

• Working with window form components

III. I/O Stream


C Sharp (C#)
• C# was designed by Anders Hejlsberg from Microsoft in 2000.

• C# is a general-purpose, multi-paradigm programming language.


• Console App., C# ASP.NET, Window form, .NET framework 1/2/3/4/5/6, .NET Core 6.0

• C# is a compiling language (vs. scripting language such as PHP, JavaScript, Python).


• Compiling C# -> Bytecode ( .NET Runtime) -> Machine code, Java -> Bytecode (Java Virtual Machine) -> Machine code , C ->
Assembly/Machine code

• Scripting/trans-scripting language: JS/nodeJS (V8 Engine, browser), Ruby -> JVM Bytecode.

• Static typing, strong typing, lexically scoped,  functional, generic, object-oriented (class-


based), and component-oriented programming disciplines.
C# fundamental syntax
• Class and function access levels using System; // this is the start of all c# program

are: protected, private, public


namespace HelloWorld // th
• Start/end of a code block : {} {
public class Program
• End of a line with semi-colon {
More: static void Main(string[] args)
{
https://www.w3schools.com/cs/cs int a = 1 + 2;
_syntax.php
string name = "Class";
Console.WriteLine("Hello World!" + name + a);

}
}
}
C# Window form
• Windows Forms (WinForms) is a free and open-
source graphical (GUI) class library included as a part
of Microsoft .NET, .NET Framework or Mono
Framework, embedded in Window Foundation Class
Library
• Became OSS in 2018:
https://github.com/dotnet/winforms
• A Windows Forms application is an 
event-driven application supported by Microsoft's 
.NET Framework. Window form application constantly
listens for events such as: key pressed, left-click, right
click, …
C# Window form layout
C# Window form – component controls

• Buttons
• Label
• RichTextBox
• Textbox
C# Window form – open a file
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.FileName = "";
dlg.Filter = "*.jpeg|*.jpg|*.*|*.*";
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
_errormessage = "";
_filename = dlg.FileName;
_importMissing = System.Windows.Forms.MessageBox.Show(
}
}
References
• C# Winform Tutorial:
https://docs.microsoft.com/en-us/visualstudio/ide/create-csharp-winf
orm-visual-studio?view=vs-2022
Assignment Week #2
• C# Window form Calculator
• UI looks like the next figure
• Can peform +, -, x, / and % (mod)

• C# Window form picture viewer:


• Open a folder path using OpenFileDialog
• Read of the image files inside that folder
• Display a list of thumbnail of those images and display the chosen image on
the main Picturebox, user should be able to navigate through all images using
left-right arrows key on the keyboard.

You might also like