Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Copyright © 2004-2013 Curt Hill More Components Varying the input of Dev-C++ Windows Programs."— Presentation transcript:

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

2 Which Widgets? Menus Memos Check boxes Radio buttons List Boxes Copyright © 2004-2013 Curt Hill

3 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 menu Copyright © 2004-2013 Curt Hill

4 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

5 Initially Copyright © 2004-2013 Curt Hill

6 Dropped Copyright © 2004-2013 Curt Hill

7 Click Menu Items Copyright © 2004-2013 Curt Hill

8 After Enter Copyright © 2004-2013 Curt Hill

9 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

10 After clicking add item Copyright © 2004-2013 Curt Hill

11 After clicking Create SubMenu Copyright © 2004-2013 Curt Hill

12 Basic Menu Design Copyright © 2004-2013 Curt Hill

13 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

14 Add Event Copyright © 2004-2013 Curt Hill

15 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

16 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

17 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

18 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

19 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

20 Starting Copyright © 2004-2013 Curt Hill

21 After Setting Copyright © 2004-2013 Curt Hill

22 Closed Copyright © 2004-2013 Curt Hill

23 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

24 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

25 Radio Buttons Copyright © 2004-2013 Curt Hill

26 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

27 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

28 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 this Copyright © 2004-2013 Curt Hill

29 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

30 List Boxes Way to choose one from many Shows only a few, but allows scrolling Items is the property that holds the lines Multiple items may be selected if a property is set Copyright © 2004-2013 Curt Hill

31 wxListBox Items edited with the String List Editor GetSelection tells which is selected Zero based Selection does not show in object inspector If nothing selected then -1 GetString(int) will show you the item corresponding to any number Copyright © 2004-2013 Curt Hill

32 Caution We may get the string like this: List1->GetString( List1->GetSelection()) If this is used and no item is selected then the program will be aborted Use an if to protect against that -1 return value Copyright © 2004-2013 Curt Hill

33 Code int i = List1->GetSelection(); if(i >= 0) Memo1->AppendText( List1->GetString(i)); else Memo1->AppendText( "Nothing selected\n"); Copyright © 2004-2013 Curt Hill

34 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


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

Similar presentations


Ads by Google