Graphical User Interface GUI l A GUI allows

  • Slides: 11
Download presentation
Graphical User Interface (GUI) l. A GUI allows user to interact with a program

Graphical User Interface (GUI) l. A GUI allows user to interact with a program visually. l GUIs are built from GUI components. l A GUI component is an object with which the user interacts via the mouse and keyboard.

Some basic components l l l l l Label - An area in which

Some basic components l l l l l Label - An area in which icons or text can be displayed Text. Box – An area in which user inputs data Button – An area that triggers an event when clicked Check. Box –A GUI control that is either selected or not selected Combo. Box – A drop-down list of items from which the user can make a selection List. Box – An area in which a list of items is displayed Panel – A container in which components can be placed HScroll. Bar – A horizontal scroll bar. VScroll. Bar – A vertical scroll bar.

Window form l. A form is a graphical element that appears on the desktop.

Window form l. A form is a graphical element that appears on the desktop. l A form can be a dialog, an SDI window (single document interface window) or an MDI window (multiple document interface window)

Form property and events l Common properties ¡ Accept. Button – specifies which button

Form property and events l Common properties ¡ Accept. Button – specifies which button will be clicked when user press enter ¡ Auto. Scroll – specifies whether scrollbars appear when needed ¡ Cancel. Button – specifies which button is clicked when user presses Esc ¡ Form. Border. Style – specifies the border of the form ¡ Font -specifies the font of text displayed in the form as well as the default font of controls added to the form ¡ Text – specifies the text in the form’s title bar

Form properties and events l Common methods ¡ Close – closes form. ¡ Hide

Form properties and events l Common methods ¡ Close – closes form. ¡ Hide – hides form ¡ Show – display a hidden form l Common ¡ Load events – occurs before a form is shown

Basic event handling l Double-click the click event in the property window to create

Basic event handling l Double-click the click event in the property window to create an empty event handler in the program code private: System: : void form. Name_Click(System: : Object *sender, System: : Event. Args *e) { Message. Box: : Show(S”Form was pressed”); };

Register event-handler with delegate After creating the event-handler, we must register it with the

Register event-handler with delegate After creating the event-handler, we must register it with the delegate, which contains a list of event handlers to call. l Controls have a delegate for each of their events l The delegate has the same name as the event l If we are handling event Event. Name for object my. Control, then the delegate pointer is my. Control->Event. Name l. NET registers events for us this->Click += new System: : Event. Handler(this, Form 1_Click); l The first argument to the Event. Handler constructor is a pointer to the object that contains the method specified as the second argument. l Form 1_click is a method of class Form 1. The first argument will be 0 if the method is static method l

Control properties l l l l Back. Color: background color of the control Text:

Control properties l l l l Back. Color: background color of the control Text: text associated with the control Text. Align: The alignment of the text on the control. Font: Font used to display control’s text Fore. Color: Foreground color of the control. Usually color of the text Focused: specifies whether the control has focus Visible: specifies whether the control is visible

Common methods l Focus: Transfer the focus to the control l Hide: Hides the

Common methods l Focus: Transfer the focus to the control l Hide: Hides the control( equivalent to setting Visible to false) l Show: shows the control(equivalent to setting Visible to true)

Control layout Anchor: anchoring allows control to stay a fixed distance from the sides

Control layout Anchor: anchoring allows control to stay a fixed distance from the sides of the container, even when the control is resized l Dock: docking allows control to extend themselves along the sides of their containers l Fill dock option effectively docks the control to all sides of its parent l Dockpadding sets the distance from docked controls to the edge of the form. l

Create window form project l From File->new -> project l Select window form application(.

Create window form project l From File->new -> project l Select window form application(. Net) l Click view->toolbox if toolbox is not open l Drag and drop the controls to design GUI