210 likes | 490 Views
CIS 338: Additional Controls. Dr. Ralph D. Westfall April, 2011. Additional Interface Controls. TextBoxes, ListBoxes, Buttons, etc. are relatively simple parts of an interface VB.NET offers some more complex controls
E N D
CIS 338: Additional Controls Dr. Ralph D. Westfall April, 2011
Additional Interface Controls • TextBoxes, ListBoxes, Buttons, etc. are relatively simple parts of an interface • VB.NET offers some more complex controls • MenuStrips make it possible to choose from multiple items, in an organized fashion • ToolStrips provide a graphic way (icons) for users to select actions
Possible Menus in Applications • File menu if your program uses files for input and/or output • Edit menu – could use code to copy, cut and paste data in your TextBox controls • Windows – can have more than 1 with VB's Multiple Document Interface (MDI)
Menu Issues • menu = choices for user • usually drop down and give more choices • make menu items similar to common ones, where possible • e.g., File, Edit, View, Tools, Window, Help • easier to learn and use • don't force users into this pattern if your choices don't fit well with common ones
Setting Up a MenuStrip • drag/drop a MenuStrip control from Toolbox (Windows Forms) onto form • [click in "tray" below form to get focus] • type in caption in Type Here at form top • put & before keyboard shortcut letter • add subItem choices below where it says Type Here • add new items on right
MenuStrip Shortcuts • can use Alt key for top level selections • [Alt] first letter is default top level shortcut • put & before any other letter for top level menu shortcutting (F&ormat) • underscore will show when press Alt key • setting up shortcut key (combinations) to select without using menu • drop down helps create combinations • best to follow common patterns • e.g., make copy be Ctrl-C (Ctrl+C)
Multiple Level Issues • naming convention: mnu[top][2nd][3rd] • set in properties window • e.g., mnuFileNewWindow (IE browser) • triangle on right points to a submenu • … (3) dots after text means get more information (i.e., leads to a dialog box) • shortcut key shows on right if set = True
Other Menu Item Capabilities • click dropdown triangle in Type Here • select Separator to create horizontal bar • has a name, just like other menu items • can also put a ComboBox or Textbox in menu to provide more choices for user or allow to type in a choice
Invisible Menu Choices • can use for choices that show up with rest of menu items based on a user action e.g., • when another (not a child) form is visible • can create in Menu Editor like others • add a new top level choice to an existing menu • uncheck Visible for top level item
Invisible Menu Choices - 2 • identify the event that will trigger the specified menu to become visible • create code for an event handler (e.g. double click a Button) • type code in the handler to show the menu • mnu[ ].Visible = True
Code for Menu Items • click lowest level items (on form) • 2nd level items if 2 levels • usually wouldn't add an action until get to lowest level menu item • type in code to handle selection in window • example: MsgBox(" [ ] menu item OK")
Multiple Level Menus • top level choices open second levels • 2nd opens 3rd, etc. • e.g., Tools>Macros>Macros IDE … (VB) • e.g., View>TextSize>Larger (IE) • VB.NET allows many levels ( >10 ) • how many menu levels are too much? • HCI (human computer interaction) experts: limit menu levels to not more than 3 (3 or less)
VB ToolStrips • icons to control program • e.g., at top of screen in IE, Word, etc. • when user clicks, runs a command or changes a setting • e.g., sends to printer, changes font size
Adding a ToolStrip • select ToolStrip control and drop on form • change Anchor property if desired • use dropdown to select items for it • adjust properties of added items, as desired
Configuring ToolStrip Buttons • right click ToolStrip for options • Insert Standard Buttons provides buttons commonly used in Microsoft applications • set item values in Properties window • use a meaningful Name (btn[name]) • set ToolTipText property for text to show on a mouseover
ToolStrip Buttons - 2 • set DisplayStyle to appropriate value • Image or Text • set Style to appropriate value (previous versions) • PushButton – runs code • ToggleButton – on/off • like B button for bold in Office • DropDownButton – drop down menu
ToolStripMenuItem Properties • some ToolStripMenuItem properties • Checked – if True, shows check on item • Enabled – False means grayed out • Visible – can't see it if this property is False • ToolTipText – show explanatory information for the menu item when user mouses over it
ToolStripMenuItem Properties • additional properties • Text – menu text • Name – object's name in code • ShortcutKeys – special key(s) that can run code instead of clicking menu • function keys (F1, etc.) • key combinations ( [Ctrl] [Z] ) • ShowShortcutKeys defaults to True
Coding ToolStrip Buttons • click on ToolStrip button to get into Code window • add code as desired
Coding ToolStrips • can add buttons in code 'general declarations Dim btnExit As New ToolStripButton() 'in a Sub btnExit.Text = "Exit" ToolStrip1.Buttons.Add(btnExit)
ImageList Being Deprecated? • in Components section of Toolbox now • drag and drop it onto form • right click it, select Properties, click … (3 dots) by Images property • click Add button (get from directory): • Microsoft Visual Studio Graphicsthese images are in some folder in your Visual Studio installation (can someone find it?) • select pictures