Mekdela Amba University
College of Informatics
Department of computer
science
ComboBox and Menu
Prepared by: Msge
Desta
ComboBox Control
is allowing a user to choose from a set of options.
looks like a text box with a button in its right side.
When the button is clicked, the ComboBox show a drop-down
box containing the list of options/items available. The user can
then choose from these options by clicking one of them. The
selected option will then be the text inside the ComboBox.
some of properties of the ComboBox control:
DataSource : A list of data that the control will
use to get its items.
DropDownHeight: The height in pixels of the dropdown box in a
combo box.
FormatString: The format specifier characters that indicate how a
value is to be displayed.
Items: The items in the combo box.
Sorted: Specifies whether the items on the
combo box should be sorted.
Text: The default text when there is no
item selected.
SelectedIndex: Gets or sets the selected index. Every item has an
index starting from 0 to (number of items - 1). A value of -1 indicates
that no item is selected.
SelectedItem: Gets or sets the item of the currently selected item
Some events of ComboBox control but default event is
SelectedIndexChanged event.
Click Occurs when the component is clicked.
DropDown Occurs when the drop-down portion of the
combo box is shown.
DropDownClosed Indicates that the drop-down portion of
the combo box has been closed.
SelectedIndexChanged Occurs when the value of the SelectedIndex the
property is changed.
Example: Place a combo box on a blank form.
Name it comboBox Names by changing the Name property.
Go to the Properties Window and find the Items property. You
should see a button with three dots in it. Click it to open the
String Collection Editor.
Alternatively, click Edit Items located below the list of
properties in the Properties Window.
In the String Collection Editor, type the names show in the
figure below then press OK.
Change the Text property to "Choose a name".
Double click the combo box will generate an event handler
for the SelectedIndexChanged event.
Type the following code inside the event handler.
Run the program and choose a name. The program will greet
the name you have selected immediately after you selected that
name.
add the items programmatically or during runtime, use
the Items property that has an Add method to add new items to
the ComboBox.
Menus
Group related commands together
that contains commands and submenus.
MainMenu and Description / Delega te and Event Arguments
MenuItem events and
properties
MainMenu Properties
MenuItems Collection of MenuItems for the MainMenu.
RightToLeft Used to display text from right to left. Useful for languages that are read
from right to left.
MenuItem Properties
Checked Whether menu item appears checked (according to property
RadioCheck). Default false, meaning that the menu item is not
checked.
Index Item’s position in parent menu.
MenuItems Collection of submenu items for this menu item.
Adding Menus to Windows Forms
add File, Edit, and View menus, with items on each menu, and
even sub menus.
Create a new Windows Application can add a menu bar form
Menus and Toolbars then Double click MenuStrip:
You'll see a menu bar appear at the top of your form:
Adding items to your menus is quite simple. Click inside of
the area at the top, where it says "Type Here". Now type the
word File.
Hit the Enter key on your keyboard.
To add items to your File menu, click inside of the second "Type Here". Now
type the word New. Hit the Enter key on your keyboard to add the menu item:
A Sub menu is one that opens out from a main menu item created by click on
menu item. Example the New item to select it. You should see a "Type Here"
box appear to the right of New: Click Inside of this box and type NEW
Project.
Menu Shortcuts
underlined letters:
hit the ALT key on your keyboard, press the key that corresponds
to the underlined letter. Pressing the "F" key, for example, will
then cause the menu to drop down. Pressing any of the
underlined letters on the File menu will implement that menu
item.
Holding down CTRL + SHIFT + N at the same time will cause
the New Project dialogue box to appear.
To add an underline to any of the letters, use the ampersand
symbol (&) before the letter you want to use as a shortcut. In
the image below, we've added an ampersand just before the
"F" of File:
The key combination shortcuts are just as easy to add. Click on
your New menu item to select it. Locate the ShortcutKeys
Property in the Properties Window.
The Modifiers are the CTRL, Shift, and ALT keys that can
select one or all of these, if you want. To activate a shortcut,
hold down these keys.
the shortcuts for the New menu item are an Underline, and Ctrl
+ N. Have a look at the next image, and add the same Shortcut
Keys to your File menu:
add code behind the menu items
Return to your form, and click the menu strip. Click the File
item to see its menu. Double click on your Quit item.
To see Cut, Copy, Paste and Undo in action, add two text
boxes to your form. Set the MultiLine Property of each text
box to true. For text box one, type anything you like for the
Text property.
Cut method:
Undo
copy
paste
Assignment Two
Within your previous group
Develop a Notepad using C#.
Deadline
30/08/17 E.C
Questions?