Computer Programming 2 windows form GUI Dr. Ahmed Taha – T.A. Ghada Adel CLI GUI CLI stands for Command Line Interface. GUI stands for Graphical User Interface. CLI GUI GUIs use visual elements such as windows, menus, and icons to interact with the computer system. CLIs require users to type commands into a terminal or console to interact with the computer. GUIs are typically more user-friendly. CLIs are typically faster and more efficient than GUIs, as they require fewer system resources. GUIs require minimal knowledge of commands and syntax. GUIs may be slower and less efficient than CLIs, as they require more system resources. CLIs can perform complex operations with a single command. CLIs have a steeper learning curve and require knowledge of command syntax. C# METHODS C# provides a wide range of built-in methods and libraries to simplify common programming tasks. A method is a block of code which only runs when it is called. You can pass data, known as parameters, into a method. Methods are used to perform certain actions, and they are also known as functions. WHY USE METHODS? TO REUSE CODE: DEFINE THE CODE ONCE, AND USE IT MANY TIMES. C# provides some pre-defined methods, which you already are familiar with, such as Main() HERE ARE SOME COMMONLY USED METHODS IN C# Console.WriteLine: This method is used to display text on the console. SIMPLE METHOD Static means that the method belongs to the Program class and not an object of the Program class. Void means that this method does not have a return value. USING METHODS METHOD PARAMETERS CLASS CLASS Class CLASS members / variables CLASS method / function CREATE OBJECT FROM CLASS SET VALUES TO THE OBJECT CREATE MULTIPLE OBJECTS FROM THE SAME CLASS Class Method inside the class to displa value on console Method parameters CONSTRUCTOR A CONSTRUTOR is a special method that is automatically called when an object is created from a class. Its primary purpose is to initialize the objects, typically by setting its member variables to default or specific values. A constructor is a special method that is used to initialize objects. The advantage of a constructor, is that it is called when an object of a class is created. It can be used to set initial values for fields: Constructor Access modifier C# EVENTS In C#, events are a way of notifying an object or method when something significant has occurred, such as a button being clicked, a file being opened, or a database record being updated. Events allow one object to notify other objects that a particular action has occurred, without the need for those objects to continuously poll for updates. Event handling function for the button click event EXAMPLE 1 Replace label text by text entered by user EXAMPLE 2 Show a new message box showing name of user PRACTICE TIME STOPWATACH GUI CODE CODE THANK YOU Dr. Ahmed Taha – T.A. Ghada Adel