Advanced Programming Introduction Engr. Muhammad Ahsan Raees
Objectives Design principles of graphical user interfaces (GUIs) How to create graphical user interfaces How to process events in response to user interactions with GUI controls The namespaces that contain the classes for GUI controls and event handling How to create and manipulate various controls How to add descriptive ToolTips to GUI controls How to process mouse and keyboard events
Introduction to GUIs GUIs allow users to interact visually with applications Built from GUI controls (components/widgets) Examples include buttons, text boxes, menus, toolbars, etc.
Windows Forms Overview A library for creating GUI applications in C# Forms are graphical elements like windows or dialogs Components are instances of classes implementing Component Controls like Button, Label, and TextBox have a graphical representation
Common GUI Controls Label : Displays text or images (non-editable) TextBox : Allows user input Button : Triggers an event when clicked CheckBox : Selectable option (checked/unchecked) ComboBox : Drop-down list for selection ListBox : Displays a list of selectable items
Event Handling in Windows Forms - GUIs are event-driven (user actions trigger events) - Common events: - Clicking a Button - Typing in a TextBox - Selecting a menu item - Moving the mouse - Event handlers respond to these interactions
Creating a Simple Event-Driven GUI - A form contains a Button control - Clicking the Button displays a MessageBox - Event handler method: ```csharp private void button_Click(object sender, EventArgs e) { MessageBox.Show("Button clicked!"); } ```