unit2

32
Unit 2 - GUI Design and Event Driven Programming Ms. Yagni Desai

Upload: abha-damani

Post on 25-May-2015

897 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Unit2

Unit 2 - GUI Design and Event Driven Programming

Ms. Yagni Desai

Page 2: Unit2

Windows Form

• It is a graphical user interface on which the information can be display, either textual or graphical.

• They are the basic object used to develop an application, it also contains the coding as well as the controls.

• It is the base on which user interface can be developed.• Forms is created by default when a Project is created with a

default name Form1. • Every form has its own Properties, Methods and Events. • The form properties name, caption are changed as required,

since multiple forms will be used in a Project.

Page 3: Unit2

Windows Form

• The support for the windows forms is provided in System.Windows.Forms namespace.

• The Form class is from System.Windows.Forms.Form namespace.

• Form class is based on Control class.• The hierarchy of the Form class:System.Object

System.MarshalByRefObject

System.ComponentModel.Component

System.Windows.Forms.Control

System.Windows.Forms.ScrollableContol

System.Windows.Forms.ContainerControl

System.Windows.Forms.Form

Page 4: Unit2

TitleControl Box

Client Area

• Title: It display the title of form.

• Control Box: Maximize, Minimize and cancel buttons.

• Client Area: the main area of the form in which user interface can be created by placing the control is called client area.

Page 5: Unit2

Property Description

Size Gets or sets the size of the form.

StartPosition Gets or sets the starting position of the form at run time.

Text Gets or sets the text associated with this form.

Visible Gets or sets a value indicating if the form is visible.

Width Gets or sets the width of the form.

WindowState Gets or sets the form's window state.

Windows Form Properties

Page 6: Unit2

Property Description

AcceptButton Gets or sets the button on the form that is pressed when the user uses the Enter key.

ActiveMdiChild Gets the currently active multiple document interface (MDI) child window.

BackColor Gets or sets the background color for this form.

BackgroundImage Gets or sets the background image in the form.

CancelButton Indicates the button control that is pressed when the user presses the ESC key.

ContextMenu Gets or sets the shortcut menu for this form.

Controls Gets or sets the collection of controls contained within the form.

Cursor Gets or sets the cursor that is displayed when the user moves the mouse pointer over this form.

Page 7: Unit2

Property Description

Enabled Gets or sets a value indicating if the form is enabled.

Focused Indicates if the form has input focus.

ForeColor Gets or sets the foreground color of the form.

Height Gets or sets the height of the form.

Icon Gets or sets the icon for the form.

IsMdiChild Indicates if the form is an MDI child form.

IsMdiContainer Gets or sets a value indicating if the form is a container for MDI child forms.

MdiChildren Returns an array of forms of the MDI child forms that are parented to this form.

MdiParent Gets or sets the current MDI parent form of this form.

Page 8: Unit2

Methods of Form

Method Description Close Closes the form.Contains Indicates if the specified control is a child of

this form.Focus Gives the form the focus.Hide Hides the form.SetDesktopLocation Sets the location of the form in desktop

coordinates.Show Makes the form display by setting the visible

property to true.ShowDialog Displays the form as a modal dialog box.

Page 9: Unit2

Events of Form

Event DescriptionLoad Occurs before a form is displayed for the first

time.Resize Occurs when the form is resized.SizeChanged Occurs when the Size property value has

changed.TextChanged Occurs when the Text property value has

changed.Click Occurs when the form is clicked.Closed Occurs when the form is closed.Load Occurs before a form is displayed for the first

time.Resize Occurs when the form is resized.

Page 10: Unit2

Label Control

• Labels usually are used to display text that cannot be edited by the user.

• They are based on the Control class.

Property Description

AutoSize Sets/gets a value specifying if the control should be automatically resized to display all its contents.

BorderStyle Sets/gets the border style for the control.

Image Sets/gets the image that is displayed on a Label.

ImageAlign Sets/gets the alignment of an image that is displayed in the control.

PreferredHeight Gets the preferred height of the control.

PreferredWidth Gets the preferred width of the control.

TextAlign Sets/gets the alignment of text in the control.

Page 11: Unit2

Link Label Control

• Link labels support hyperlinks.• It is use to make a part of the text in this control a link to a

Visual Basic object or web page.

Property Means

ActiveLinkColor Sets/gets the color for an active link.

DisabledLinkColor Sets/gets the color for a disabled link.

LinkArea Sets/gets the range in the text to treat as a link.

LinkBehavior Sets/gets a value that represents the behavior of a link.

LinkColor Sets/gets the color for a normal link.

Links Gets the collection of links in the LinkLabel control.

LinkVisited Sets/gets a value specifying if a link should be displayed as though it had been visited.

VisitedLinkColor Sets/gets the color used for links that that have been visited.

Page 12: Unit2

Event of Link Label

Event Means

LinkClicked Occurs when a link is clicked inside the link label.

Page 13: Unit2

Button Controls

• Buttons are the plain controls that you simply click and release.

• Buttons provide the most popular way of creating and handling an event in your code.

Property Means DialogResult Gets/sets the value returned to the parent form when the

button is clicked. Often used when you're creating dialog boxes.

FlatStyle Gets/sets a flat style appearance.Image Gets/sets an image displayed in a button.TextAlign Gets/sets the alignment of the text in the button.

Page 14: Unit2

Method of Button

Method Means PerformClick Causes a Click event for a button.

Page 15: Unit2

Text Box Controls

• It is box like controls in which you can enter text.• Text boxes can be multiline, have scroll bars, be read-only

and have many other attributes.• The TextBox class is derived from the TextBoxBase class,

which is based on Control.System.Windows .Forms.Control

System.Windows.Forms.TextBoxBase

System.Windows.Forms.TextBox

• The Text Box control is used to get input from the user or to display text.

• It is generally used for editable text, it can also be made read-only.

Page 16: Unit2

Properties of Text Box

Property Means

Multiline Sets/gets value specifying if this is a multiline text box control.

ReadOnly Sets/gets a value specifying if the text in the text box is read-only.

ScrollBars Sets/gets what scroll bars should appear in a multiline textbox.

TextAlign Sets/gets how text is aligned in a text box control.

PasswordChar Indicates character to display for password input for single-line edit control

Page 17: Unit2

Methods of Text Box

Methods MeansAppendText Appends text to the current text in the text box.Clear Clears all the text from the text box.Copy Copy the selected text in the text box to the

clipboard.Cut Moves the selected text in the text box to the

clipboard.Paste Replaces the selected text in the textbox with the

contents of the clipboard.Select Selects text in the textbox.SelectAll Selects all the text in the textbox.

Page 18: Unit2

Events of Text Box

Events Means

AutoSizeChanged Occurs when the value of the AutoSize property is changed.

Click Occurs when the text box is clicked.

ReadOnlyChanged Occurs when the value of the ReadOnly property is changed.

Page 19: Unit2

Check Box Control

• Checkboxes allow the user to make multiple selections from a number of options.

• You can click a check box to select it and click it again to deselect it.

Property Means Appearance Gets/sets the appearance of a checkbox.AutoCheck Specifies if the Checked or CheckState values and the checkbox's

appearance are automatically changed when the checkbox is clicked.CheckAlign Gets/sets the horizontal and vertical alignment of a checkbox in a

checkbox control.Checked Gets/sets a value indicating if the checkbox is in the checked state.CheckState Gets/sets the state of a three-state checkbox.ThreeState Specifies if the checkbox will allow three check states rather than two.

Page 20: Unit2

Events of Check Box

Event Means AppearanceChanged Occurs when the Appearance property

changes.CheckedChanged Occurs when the Checked property

changes.CheckStateChanged Occurs when the CheckState property

changes.

Page 21: Unit2

Radio Button Control

• A radio button or option button is a type of graphical user interface element that allows the user to choose only one of a predefined set of options.

• When a user clicks on a radio button, it becomes checked, and all other radio buttons with same group become unchecked.

• Use a radio button when you want the user to choose only one option.

Method Means PerformClick Generates a Click event for the radio button,

simulating a click by a user.

Page 22: Unit2

Properties & Events of Radio Button

Property Means Appearance Gets/sets the value that determines the appearance of the

radio button.

Checked Gets/sets a value indicating whether the radio button is checked.

FlatStyle Gets/sets the flat style appearance of the radio button.

TextAlign Gets/sets the alignment of the text in a radio button.

Event Means AppearanceChanged Occurs when the Appearance property changes.CheckedChanged Occurs when the value of the Checked property

changes.

Page 23: Unit2

Combo Box Control

• Combo box control is used to display data in a drop-down combo box.

• The combo box is made up of two parts:– The top part is a text box that allows the user to type part of

a list item. – The other part is a list box that displays a list of items from

which the user can select one or more.

• You can allow the user to select an item from the list, or enter their own data.

• If no item is selected, the SelectedIndex value is -1. • If the first item in the list is selected, then the

SelectedIndex value is 0.

Page 24: Unit2

ComboBox cont…

• There are three types of combobox:– DropDown (the default) - Includes a drop-down list

and a text box. The user can select from the list or type in the text box.

– Simple - Includes a text box and a list, which doesn't drop down. The user can select from the list or type in the text box.

– DropDownList - This style allows selection only from the drop-down list.

24

Page 25: Unit2

Properties of ComboBoxProperty Means DropDownStyle Gets/sets the style of the combo box.DropDownWidth Gets/sets a combo box's drop-down part's width.SelectedIndex Gets/sets the index of the currently selected item.SelectedItem Gets/sets currently selected item in the combo box.SelectedText Gets/sets the selected text in the text box part of a

combo box.

25

Page 26: Unit2

Methods of ComboBoxMethod Means

BeginUpdate Turns off visual updating of the combo box until the EndUpdate method is called.

EndUpdate Resumes visual updating of the combo box.

FindString Finds the first item in the combo box that begins with the indicated string.

FindStringExact Finds the item that matches the indicated string exactly.

GetItemText Gets an item's text.

Select Selects a range of text.

SelectAll Selects all the text in the text box of the combo box.

26

Page 27: Unit2

Events of ComboBox

• Code

27

Event Means

DropDown Occurs when the drop-down portion of a combo box is shown.

DropDownStyleChanged Occurs when the DropDownStyle property has changed.

SelectedIndexChanged Occurs when the SelectedIndex property has changed.

Page 28: Unit2

Listbox

• list boxes display a list of items from which the user can select one or more.

• If there are too many items to display at once, a scroll bar automatically appears to let the user scroll through the list.

• In Visual Basic .NET, each item in a list box is itself an object.

Page 29: Unit2

Listbox

• The SelectionMode property determines how many list items can be selected at a time; you can set this property as:– MultiExtended— Multiple items can be selected, and

the user can use the Shift, Ctrl, and arrow keys to make selections.

– MultiSimple— Multiple items can be selected.

– None— No items may be selected.

– One— Only one item can be selected.

Page 30: Unit2

Listbox PropertiesProperties Meaning

MultiColumn You also can scroll list boxes horizontally when you set this property to True

ScrollAlwaysVisible if True, a scroll bar always appears.

SelectedIndex Gets/sets the index of the currently selected item.SelectedItem Gets/sets currently selected item in the combo

box.Sorted: Default value is set to False. Set it to True if you

want the items displayed in the ListBox to be sorted by alphabetical order.

Page 31: Unit2

Listbox MethodsMethod UseCount Counting the number of Items in a ListBox RemoveAt() You can remove all items or one particular item from the

list box. Clear() To remove all items.

Page 32: Unit2

Listbox Event

• CodeSelectedIndexChanged Occurs when the SelectedIndex property has changed.