Graphical User Interface 2.0

– Menus provide groups of related commands for Windows applications

– The menu that contains a menu item is called that menu item’s parent menu. A menu item that contains a submenu is considered to be the parent of that submenu

– All menu items can have Alt key shortcuts (also called access shortcuts or hotkeys), which are accessed by pressing Alt and the underlined letter (for example, Alt F typically expands the File menu). Menus that are not top-level menus can have shortcut keys as well (combinations of Ctrl, Shift, Alt, F1, F2, letter keys, etc.). Some menu items display check marks, usually indicating that multiple options on the menu can be selected at once

– To create an access shortcut (or keyboard shortcut), type an ampersand (&) before the character to be underlined

– Menu items can be grouped logically by separator bars,f which are inserted by right clicking the menu and selecting Insert Separator or by typing "-" for the text of a menu item

– Menu Strip Properties:

o MenuItems: Contains the top-level menu items for this MenuStrip

o HasChildren: Indicates whether MenuStrip has any child controls (menu items)

o RightToLeft: Causes text to display from right to left. This is useful for languages that are read from right to left

- ToolStripMenuItem Properties:

o Checked: Indicates whether a menu item is checked. The default value is false, meaning that the menu item is unchecked

o CheckOnClick: Indicates that a menu item should appear checked or unchecked as the item is clicked

o Index: Specifies an item’s position in its parent menu. A value of 0 places the MenuItem at the beginning of the menu

o MenuItems: Lists the submenu items for a particular menu item

o ShortcutKeyDisplayString: Specifies text that should appear beside a menu item for a shortcut key. If left blank, the key names are displayed. Otherwise, the text in this property is displayed for the shortcut key

o ShortcutKeys: Specifies the shortcut key for the menu item (e.g., <Ctrl>-F9 is equivalent to clicking a specific item)

o ShowShortcutKeys: Indicates whether a shortcut key is shown beside menu item text. The default is true, which displays the shortcut key

o Text: Specifies the menu item’s text. To create an Alt access shortcut, precede a character with & (e.g., &File to specify a menu named File with the letter F underlined)

– Common Events:

o Click: Generated when an item is clicked or a shortcut key is used. This is the default event when the menu is double clicked in the designer

– It is a convention to place an ellipsis (...) after the name of a menu item that when selected, displays a dialog (e.g. Save As…). Menu items that produce an immediate action without prompting the user for more information (e.g. Save) should not have an ellipsis following their name

- The .NET Framework provides two controls that allow an application to retrieve date and time informationthe MonthCalendar and DateTimePicker

- Month Calendar Properties:

o FirstDayOfWeek: Sets which day of the week is the first displayed for each week in the calendar

o MaxDate:

o MaxSelectionCount: The maximum number of dates that can be selected at once

o MinDate: The first date that can be selected

o MonthlyBoldedDates: An array of dates that will displayed in bold in the calendar

o SelectionEnd: The last of the dates selected by the user

o SelectionRange: The dates selected by the user

o SelectionStart: The first of the dates selected by the user

– Common Events:

o DateChanged: Generated when a date is selected in the calendar

DateTimePicker Properties

o CalendarForeColor: Sets the text color for the calendar

o CalendarMonthBackground: Sets the calendar’s background color

o CustomFormat: Sets the custom format string for the user’s options

o Format: Sets the format of the date and/or time used for the user’s options

o MaxDate: The maximum date and time that can be selected

o MinDate: The minimum date and time that can be selected

o ShowCheckBox: Indicates if a CheckBox should be displayed to the left of the selected date and time

o ShowUpDown: Used to indicate that the control should have up and down Buttons. This is helpful for instances when the DateTimePicker is used to select a time the Buttons can be used to increase or decrease hour, minute and second values

o Value: The data selected by the user

– Common Events:

o ValueChanged: Generated when the Value property changes, including when the user selects a new date or time

– The LinkLabel control displays links to other resources, such as files or Web pages

– Class LinkLabel is derived from class Label and therefore inherits all of class Label‘s functionality

– Common Properties:

o ActiveLinkColor: Specifies the color of the active link when clicked

o LinkArea: Specifies which portion of text in the LinkLabel is part of the link

o LinkBehavior: Specifies the link’s behavior, such as how the link appears when the mouse is placed over it

o LinkColor: Specifies the original color of all links before they have been visited. The default color is set by the system, but is usually blue

o LinkVisited: If true, the link appears as though it has been visited (its color is changed to that specified by property VisitedLinkColor). The default value is false

o Text: Specifies the control’s text

o UseMnemonic: If true, the & character in the Text property acts as a shortcut (similar to the Alt shortcut in menus)

o VisitedLinkColor: Specifies the color of visited links. The default color is set by the system, but is usually purple

– Common Events (Event arguments LinkLabelLinkClickedEventArgs):

o LinkClicked: Generated when the link is clicked. This is the default event when the control is double clicked in Design mode

– method Start of class Process (namespace System.Diagnostics), which allows you to execute other programs from an application. Method Start can take one argument, the file to open (a string), or two arguments, the application to run and its command-line arguments (two strings). Method Start‘s arguments can be in the same form as if they were provided for input to the Windows Run command (Start > Run…). For applications that are known to Windows, full path names are not needed, and the .exe extension often can be omitted. To open a file that has a file type that Windows recognizes, simply use the file’s full path name. The Windows operating system must be able to use the application associated with the given file’s extension to open the file

– he @ symbol that we placed before "C:\" indicates that all characters in the string should be interpreted literallyThus, the backslash within the string is not considered to be the first character of an escape sequence. This simplifies strings that represent directory paths, since you do not need to use \\ for each \ character in the path

– The ListBox control allows the user to view and select from multiple items in a list. ListBoxes are static GUI entities, which means that items must be added to the list programmatically. The user can be provided with TextBoxes and Buttons with which to specify items to be added to the list, but the actual additions must be performed in code

ListBox properties:

o Items: The collection of items in the ListBox

o MultiColumn: Indicates whether the ListBox can break a list into multiple columns. Multiple columns eliminate vertical scrollbars from the display

o SelectedIndex: Returns the index of the selected item. If no items have been selected, the property returns -1. If the user selects multiple items, this property returns only one of the selected indices. For this reason, if multiple items are selected, you should use property SelectedIndices

o SelectedIndices: Returns a collection containing the indices for all selected items

o SelectedItem: Returns a reference to the selected item. If multiple items are selected, it returns the item with the lowest index number

o SelectedItems: Returns a collection of the selected item(s)

o SelectionMode: Determines the number of items that can be selected, and the means through which multiple items can be selected. Values None, One, MultiSimple (multiple selection allowed) or MultiExtended (multiple selection allowed using a combination of arrow keys or mouse clicks and Shift and Ctrl keys)

o Sorted: Indicates whether items are sorted alphabetically. Setting this property’s value to true sorts the items. The default value is false

– Common Methods:

o ClearSelected: Deselects every item

o GetSelected: Takes an index as an argument, and returns true if the corresponding item is selected

– Common Events:

o SelectedIndexChanged: Generated when the selected index changes. This is the default event when the control is double clicked in the designer

o CheckedListBox properties(All the ListBox properties, methods and events are inherited by CheckedItems: Contains the collection of items that are checked. This is distinct from the selected item, which is highlighted (but not necessarily checked). [Note: There can be at most one selected item at any given time]

o CheckedIndices: Returns indices for all checked items

o SelectionMode: Determines how many items can be checked. The only possible values are One (allows multiple checks to be placed) or None (does not allow any checks to be placed)

– Common Methods:

o GetItemChecked: Takes an index and returns true if the corresponding item is checked

- Common Event (Event arguments ItemCheckEventArgs)

o ItemCheck: Generated when an item is checked or unchecked

ItemCheckEventArgs Properties

o CurrentValue: Indicates whether the current item is checked or unchecked. Possible values are Checked, Unchecked and Indeterminate

o Index: Returns the zero-based index of the item that changed

o NewValue: Specifies the new state of the item

ComboBox properties:

o DropDownStyle: Determines the type of ComboBox. Value Simple means that the text portion is editable, and the list portion is always visible. Value DropDown (the default) means that the text portion is editable, but the user must click an arrow button to see the list portion. Value DropDownList means that the text portion is not editable, and the user must click the arrow button to see the list portion

o Items: The collection of items in the ComboBox control

o MaxDropDownItems: Specifies the maximum number of items (between 1 and 100) that the drop-down list can display. If the number of items exceeds the maximum number of items to display, a scrollbar appears

o SelectedIndex: Returns the index of the selected item. If there is no selected item, -1 is returned

o SelectedItem: Returns a reference to the selected item

o Sorted: Indicates whether items are sorted alphabetically. Setting this property’s value to true sorts the items. The default is false

– Common Events:

o SelectedIndexChanged: Generated when the selected index changes (such as when a different item is selected). This is the default event when control is double clicked in the designer

– The treeView control displays nodes hierarchically in a tree. Traditionally, nodes are objects that contain values and can refer to other nodes. A parent node contains child nodes, and the child nodes can be parents to other nodes. Two child nodes that have the same parent node are considered sibling nodes. A tree is a collection of nodes, usually organized in a hierarchical manner. The first parent node of a tree is the root node (a treeView can have multiple roots). For example, the file system of a computer can be represented as a tree. The top-level directory (perhaps C:) would be the root, each subfolder of C: would be a child node and each child folder could have its own children. TReeView controls are useful for displaying hierarchal information, such as the file structure that we just mentioned

– A parent node can be expanded or collapsed by clicking the plus box or minus box to its left. Nodes without children do not have these boxes

– The nodes in a treeView are instances of class treeNode. Each TReeNode has a Nodes collection (type treeNodeCollection), which contains a list of other treeNodes known as its children. The Parent property returns a reference to the parent node (or null if the node is a root node).

treeView properties:

o CheckBoxes: Indicates whether CheckBoxes appear next to nodes. A value of TRue displays CheckBoxes. The default value is false

o ImageList: Specifies an ImageList object containing the node icons. An ImageList object is a collection that contains Image objects

o Nodes: Lists the collection of treeNodes in the control. It contains methods Add (adds a treeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all of its children

o SelectedNode: The selected node

- Common Events:

o AfterSelect: Generated after selected node changes. This is the default event when the control is double clicked in the designer

TReeNode properties:

o Checked: Indicates whether the treeNode is checked (CheckBoxes property must be set to true in the parent treeView)

o FirstNode: Specifies the first node in the Nodes collection (i.e., the first child in the tree)

o FullPath: Indicates the path of the node, starting at the root of the tree

o ImageIndex: Specifies the index of the image shown when the node is deselected

o LastNode: Specifies the last node in the Nodes collection (i.e., the last child in the tree)

o NextNode: Next sibling node

o Nodes: Collection of TReeNodes contained in the current node (i.e., all the children of the current node). It contains methods Add (adds a treeNode object), Clear (deletes the entire collection) and Remove (deletes a specific node). Removing a parent node deletes all of its children

o PrevNode: Previous sibling node

o SelectedImageIndex: Specifies the index of the image to use when the node is selected

o Text: Specifies the TReeNode‘s text

– Common Methods:

o Collapse: Collapses a node

o Expand: Expands a node

o ExpandAll: Expands all the children of a node

o GetNodeCount: Returns the number of child nodes

– The ListView control is similar to a ListBox in that both display lists from which the user can select one or more items. The important difference between the two classes is that a ListView can display icons next to the list items

ListView properties:

o Activation: Determines how the user activates an item. This property takes a value in the ItemActivation enumeration. Possible values are OneClick (single-click activation), TwoClick (double-click activation, item changes color when selected) and Standard (double-click activation, item does not change color)

o CheckBoxes: Indicates whether items appear with CheckBoxes. true displays CheckBoxes. The default is false

o LargeImageList: Specifies the ImageList containing large icons for display

o Items: Returns the collection of ListViewItems in the control

o MultiSelect: Determines whether multiple selections are allowed. The default is True, which enables multiple selection

o SelectedItems: Gets the collection of selected items

o SmallImageList: Specifies the ImageList containing small icons for display

o View: Determines appearance of ListViewItems. Possible values are LargeIcon (large icon displayed, items can be in multiple columns), SmallIcon (small icon displayed, items can be in multiple columns), List (small icons displayed, items appear in a single column), Details (like List, but multiple columns of information can be displayed per item) and Tile (large icons displayed, information provided to right of icon, valid only in Windows XP or later)

– Common Events:

ItemActivate: Generated when an item in the ListView is activated. Does not contain the specifics of which item is activated

ListView allows you to define the images used as icons for ListView items. To display images, an ImageList component is required. Create one by dragging it to a Form from the ToolBox. Then, select the Images property in the Properties window to display the Image Collection Editor . Here you can browse for images that you wish to add to the ImageList, which contains an array of Images. Once the images have been defined, set property SmallImageList of the ListView to the new ImageList object. Property SmallImageList specifies the image list for the small icons. Property LargeImageList sets the ImageList for large icons. The items in a ListView are each of type ListViewItem. Icons for the ListView items are selected by setting the item’s ImageIndex property to the appropriate index

- The TabControl control creates tabbed windows, such as the ones we have seen in Visual Studio. This allows you to specify more information in the same space on a Form

– TabControls contain TabPage objects, which are similar to Panels and GroupBoxes in that TabPages also can contain controls. You first add controls to the TabPage objects, then add the TabPages to the TabControl. Only one TabPage is displayed at a time. To add objects to the TabPage and the TabControl, write:

o myTabPage.Controls.Add(myControl)

o myTabControl.Controls.Add(myTabPage)

– The main application window of an MDI program is called the parent window, and each window inside the application is referred to as a child window. Although an MDI application can have many child windows, each has only one parent window. Furthermore, a maximum of one child window can be active at once. Child windows cannot be parents themselves and cannot be moved outside their parent. Otherwise, a child window behaves like any other window (with regard to closing, minimizing, resizing, etc.). A child window’s functionality can be different from the functionality of other child windows of the parent

– To create an MDI Form, create a new Form and set its IsMdiContainer property to TRue. The Form changes appearance

– Next, create a child Form class to be added to the Form. To do this, right click the project in the Solution Explorer, select Project > Add Windows Form… and name the file. Edit the Form as you like. To add the child Form to the parent, we must create a new child Form object, set its MdiParent property to the parent Form and call the child Form’s Show method. In general, to add a child Form to a parent, write

o ChildFormClass childForm = New ChildFormClass();

o childForm.MdiParent = parentForm;

o childForm.Show();

– In most cases, the parent Form creates the child, so the parentForm reference is this. The code to create a child usually lies inside an event handler, which creates a new window in response to a user action. Menu selections (such as File, followed by a submenu option of New, followed by a submenu option of Window) are common techniques for creating new child windows

MDI Child properties:

o IsMdiChild: Indicates whether the Form is an MDI child. If true, Form is an MDI child (read-only property)

o MdiParent: Specifies the MDI parent Form of the child

– Common MDI Parent Properties

o ActiveMdiChild: Returns the Form that is the currently active MDI child (returns null if no children are active)

o IsMdiContainer: Indicates whether a Form can be an MDI parent. If True, the Form can be an MDI parent. The default value is false

o MdiChildren: Returns the MDI children as an array of Forms

– Common Method:

o LayoutMdi: Determines the display of child forms on an MDI parent. The method takes as a parameter an MdiLayout enumeration with possible values ArrangeIcons, Cascade, TileHorizontal and TileVertical.

– Common Event:

o MdiChildActivate: Generated when an MDI child is closed or activated

– Child windows can be minimized, maximized and closed independently of each other and the parent window

– In Visual inheritance, the derived Form class contains the functionality of its Form base class, including any base-class properties, methods, variables and controls. The derived class also inherits all visual aspectssuch as sizing, component layout, spacing between GUI components, colors and fontsfrom its base class

– Visual inheritance enables you to achieve visual consistency across applications. For example, you could define a base Form that contains a product’s logo, a specific background color, a predefined menu bar and other elements. You then could use the base Form throughout an application for uniformity and branding

– To create a new control composed of existing controls, use class UserControl. Controls added to a custom control are called constituent controls

Custom Control Techniques:

o Inherit from Windows Forms control: You can do this to add functionality to a pre-existing control. If you override method OnPaint, call the base class’s OnPaint method. Note that you only can add to the original control’s appearance, not redesign it

o Create a UserControl: You can create a UserControl composed of multiple pre-existing controls (e.g., to combine their functionality). Note that you cannot override the OnPaint methods of custom controls. Instead, you must place drawing code in a Paint event handler. Again, note that you only can add to the original control’s appearance, not redesign it

o Inherit from class Control: Define a brand new control. Override method OnPaint, then call base class method OnPaint and include methods to draw the control. With this method you can customize control appearance and functionality

PaintEventArgs Properties

o Graphics: The graphics object of the control. It is used to draw on the control

o ClipRectangle: Specifies the rectangle indicating the boundary of the control

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s