+ All Categories
Home > Documents > Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Date post: 13-Dec-2015
Category:
Upload: bernard-norman
View: 219 times
Download: 2 times
Share this document with a friend
Popular Tags:
30
Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs
Transcript
Page 1: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Copyright © 2004-2013 Curt Hill

More Components

Varying the input of Dev-C++ Windows Programs

Page 2: 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

Page 3: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 4: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 5: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Initially

Copyright © 2004-2013 Curt Hill

Page 6: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Dropped

Copyright © 2004-2013 Curt Hill

Page 7: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Click Menu Items

Copyright © 2004-2013 Curt Hill

Page 8: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

After Enter

Copyright © 2004-2013 Curt Hill

Page 9: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 10: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

After clicking add item

Copyright © 2004-2013 Curt Hill

Page 11: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

After clicking Create SubMenu

Copyright © 2004-2013 Curt Hill

Page 12: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Basic Menu Design

Copyright © 2004-2013 Curt Hill

Page 13: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 14: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Add Event

Copyright © 2004-2013 Curt Hill

Page 15: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 16: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 17: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 18: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 19: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 20: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Starting

Copyright © 2004-2013 Curt Hill

Page 21: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

After Setting

Copyright © 2004-2013 Curt Hill

Page 22: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Closed

Copyright © 2004-2013 Curt Hill

Page 23: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 24: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 25: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

Radio Buttons

Copyright © 2004-2013 Curt Hill

Page 26: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 27: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 28: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 29: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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

Page 30: Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs.

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


Recommended