Copyright © 2004-2013 Curt Hill
More Components
Varying the input of Dev-C++ Windows Programs
Which Widgets?
• Menus• Memos• Check boxes• Radio buttons• List Boxes
Copyright © 2004-2013 Curt Hill
Menus
• Two types:– Main menu – usually just below the
title bar– Popup – usually the result of a right
click
• What is it?– Just a specialized set of buttons
• Where: Menubars• Today we are only interested in the
main menuCopyright © 2004-2013 Curt Hill
Main Menu
• Click on wxMenuBar and drop on form
• It creates a component that does not look right until you run it
• Customize by clicking on the MenuItems entry– This brings the menu editor to front
• Then fill in the menu items
Copyright © 2004-2013 Curt Hill
Initially
Copyright © 2004-2013 Curt Hill
Dropped
Copyright © 2004-2013 Curt Hill
Click Menu Items
Copyright © 2004-2013 Curt Hill
After Enter
Copyright © 2004-2013 Curt Hill
Notes• The menu editor will allow you to
create the top level menu and submenus– We will create File and Help for top level
• We click Add Item button for each entry– Fill in caption– Click apply
• The top level menu often has no event handler
Copyright © 2004-2013 Curt Hill
After clicking add item
Copyright © 2004-2013 Curt Hill
After clicking Create SubMenu
Copyright © 2004-2013 Curt Hill
Basic Menu Design
Copyright © 2004-2013 Curt Hill
Applying Events• A menu entry should act like a button• Clicking it should take us to an event• Clicking a top level menu may only
display a submenu– The event is done for us
• Now we apply the events– Click on Create– We get a save dialog– Then next screen
Copyright © 2004-2013 Curt Hill
Add Event
Copyright © 2004-2013 Curt Hill
Menu vs. Button
• When we create an event for a button it immediately takes us to the code panel
• When we create an event for a menu it creates the event but leaves us in design mode
• We do them all then look at code
Copyright © 2004-2013 Curt Hill
One More Trick
• In the caption one ampersand may be inserted
• This causes the letter following it to be executed to be as a shortcut key
• Holding Alt and the letter is the same as clicking the mouse
• Each menu should only use a shortcut key once
Copyright © 2004-2013 Curt Hill
Multi-Line EditBox
• A normal Edit has just one line• What if we want multiple lines?• Makes a nice area to log messages
to the user• Use the Memo in Common Controls• We do handle it a little differently
than an Edit
Copyright © 2004-2013 Curt Hill
Memo in DevCPP
• The Strings property contains all the lines– Rarely is this assigned or referenced
• The AppendText method is usually used to add new material at bottom
• Escape sequences do work– Such as \n
• Use the cast to wxString and put to (<<) to display variables
Copyright © 2004-2013 Curt Hill
String List Editor
Copyright © 2004-2013 Curt Hill
• Click on the ellipsis (…) of the Strings property
• This starts the String List Editor• This sets initial values
Starting
Copyright © 2004-2013 Curt Hill
After Setting
Copyright © 2004-2013 Curt Hill
Closed
Copyright © 2004-2013 Curt Hill
Check Boxes• Easiest way to enter a boolean
value• A check box may be checked or not
– Initialized in either form
• Design property is Checked– Use GetValue or IsChecked method
• Caption property is text next to checkbox
• Typical statement might be:if(CheckBox1->IsChecked()){// do something
Copyright © 2004-2013 Curt Hill
Radio Buttons• The most visual way to choose one
out of 3 to 5• Similar to a check box but only one
may be selected• Clicking one clears all the rest• Checked is still the property• May be set at runtime by SetValue,
obtained by GetValue or IsChecked
Copyright © 2004-2013 Curt Hill
Radio Buttons
Copyright © 2004-2013 Curt Hill
Notes• Radio buttons are round and Check
boxes are square• Caption is the name next to
checkbox– Set to name
• Checked is the bool• Last one added will be checked if
none of the previous ones are checked– Will not see this in property inspector
Copyright © 2004-2013 Curt Hill
Why Just 3 – 5?
• Not an absolute rule• Two radio buttons could be
replaced by one check box• More than five radio buttons gets
to be too bulky• Use a List box for that
– It may have very many items but only uses a small space
Copyright © 2004-2013 Curt Hill
Determining Values• The Radio button also has GetValue
and IsChecked• Is that the best way to find what is
checked?• What would be needed was a series of
nested ifs:if(Radio1->IsChecked()){ … }else if(Radio2->IsChecked()){ … }else if(Radio3->IsChecked()){ … }else if(Radio4->IsChecked()){ … }
• Cannot use a switch for thisCopyright © 2004-2013 Curt Hill
Is there a better way?
• Use an enumeration• One for each radio button and one
for the unselected case• Use the On Click event handler for
the radio button to set the enumeration to this value
• When needing to decide on the radios, then use a switch on the enumeration
Copyright © 2004-2013 Curt Hill
Finally
• There are many other controls• We will not need most of these for
this class• This should give sufficient control• Now is the time for the demo
Copyright © 2004-2013 Curt Hill
Top Related