codemorphis.com Forum Index codemorphis.com
Software development: pure and simple.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Programming Tip #4: Creating Menus in a Windows Form

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    codemorphis.com Forum Index -> Visual Programming Forum
View previous topic :: View next topic  
Author Message
CodeMorphis



Joined: 02 Dec 2003
Posts: 252

PostPosted: Wed Jan 21, 2004 12:04 pm    Post subject: Programming Tip #4: Creating Menus in a Windows Form Reply with quote

Programming Tip #4: Creating Menus in a Windows Form

In this programming article, we demonstrate how to create menus and menu items in the toolbar of a Windows Form. We will also look at how to put the control logic behind this type of user interface to respond to a user's mouse and keyboard entries.


  1. In Synopsis, press Ctrl-T to bring up the component tray and click on the "Windows" tab. Drag and drop the Windows Form component onto the workspace area.

    Double click the new Windows Form that appears to bring up the Windows Form property page. If you scroll down to the bottom of the property page you will see a GroupBox titled "Menu Items".



  2. Click on the "Add" button and you will see a new menu item appear in the menu items box. Click on the menu item in the box to fill the menu item property set on the right side:



  3. You can change the text of the selected menu item as well as other characteristics of the menu item. Change the text to "File".

  4. Now let's add a sub menu item to the File menu item. Click on the "Add Sub Menu" button. Click on the new sub menu item that appears and change its text to "Open...".

  5. Select the "F1" shortcut for the "Open..." sub menu item. The shortcut is the key that is associated with the menu item. When the program is running and the user presses the shortcut key, the menu item gets activated.

  6. Click on the "File" menu item and then click the "Add Sub Menu" button again. This will add another sub menu item below the "Open..." sub menu item. The order of the menu items in the box determines the order in which the menu items appear in the Windows Form.

  7. Change the text for the new sub menu item to "Exit". Click on the "Update" button at the bottom of the property page. This will refresh our Windows Form with the given property values. Our Windows Form now has a menu bar. If we click on the "File" item we will see the results of our labour:



  8. Go back to the property page and select the "File" menu item again. Add another sub menu item. Change the text to "-" (the dash character). Select the "Exit" item and click on the ">" button. This will shift the position of the "Exit" item down so that we have the order: "Open...", "-", "Exit". A menu item entry with text "-" is windows code for specifying an item separator bar. Press the "Update" button again and look at the Windows Form menu bar:




Now that we have created our menubar interface, let's add some simple code behind it. We will make a simple program that opens up the file browser when the user clicks on the "File | Open..." item.


  1. From the component tray, drag and drop the "Windows Event" component from the "Windows" tab to the workspace area.
  2. Drag and drop the following components from the component tray onto the workspace:

    • The "File Browser" component from the "File" tab.
    • The "Switch" component from the "Logic" tab.

  3. Double click the Switch component and set the "Number of switch arguments" property to 2.
  4. Connect the components in the workspace as follows:



  5. Right click the Switch component and select "Input Argument(s)". Set the "Switch Argument 1" value to "Open..." and "Switch Argument 2" value to "Exit".


Now press the Run button in the Synopsis toolbar. If you click on the "File | Open..." menu item or press the F1 button the file browser appears, giving the typical behaviour in most Windows programs. If you click on the "File | Exit" menu item the program terminates.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    codemorphis.com Forum Index -> Visual Programming Forum All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group