![]() 3D 3D Photo Gallery (Part 1) 3D Photo Gallery (Part 2) Audio Poor Man's MIDI Make A Metronome iPod Tricks (Part 1) iPod Tricks (Part 2) iPod Tricks (Part 3) Laugh Track Machine Audio Player with Reverb Shepard Melody RB Phone Home Build a Drum Machine Custom Controls and Windows Double Click Listbox Draggable Metal Window Double Click Canvas Custom Buttons Custom Buttons Part II iTunes-style Listboxes Custom Controls General RB Scrolling Windows Using Mesage Dialogs Case-Sensitive Word Finder Introduction to Stacks Wiggle Window JPEG in PDF Listbox Checkboxes Background Applications Listbox Auto-Find Virtual Volumes Time Tracker Software Distribution (Part 1) Software Distribution (Part 2) Software Distribution (Part 3) Software Distribution (Part 4) Exceptions Tips and Tricks Text Clippings Made Easy Graphics Drawing a Simple Gradient The SpriteSurface: Space Game Image Spinner Cropping Graphics (Part 1) Cropping Graphics (Part 2) Cropping Graphics (Part 3) Cropping Graphics (Part 4) Shimmer Graphics Lissajous Figures Simple Screen Capture Vector Graphics Kaleidoscope Images Stegonography Spirals! Image Table RB Magnifying Lens Screen Capture Color Picker Tutorial Hacks Ghost Grab Speedy Mouse Extension iTunes Plugins iTunes Skinner Mac OS X Global Hot Key Event (Carbon Events) Login Welcomer (Carbon Events) Add/Remove Buttons Resizable Sheets Mac OS X Preferences Window Using Sheets in REALbasic Build a Bundle (Part 1) Build a Bundle (Part 2) Dock Your Passwords Mac OS X Debugging REALbasic Mac OS X Icon Tutorial Animate Your Dock RB and the Command Line Menus Window Menu Templates Menu Listbox Menu Novelty Guessing Game Calendar Trivia Tile Mixer Zip Code Finder Happy Valentine's Day Merlin Simulator (Part 1) Merlin Simulator (Part 2) Merlin Simulator (Part 3) Buzzword Machine AppleSoft BASIC Printing Print to PDF Registration Registration Code Validation Network Registration Codes Resources Picture Extractor (Part 1) Picture Extractor (Part 2) Serial Caller ID (Part 1) Caller ID (Part 2) Caller ID (Part 3) Speech Speech Recognition Socket Communication Easy Peer-to-Peer File Sharing MacPAD Version Checking Display Web Image In Canvas HTML IMG Tags Version Tracking Even Smarter Instant Messaging Web Tiler JavaScript and REALbasic Stock Ticker (Part I) Stock Ticker (Part 2) AIM Mate XML Manipulation Simple XML Introduction Video Big Brother Video Capture Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.
Tell us about a bad link. |
11-22-03
Listbox Menu by Seth Willits
In this tutorial, we're going to create a listbox which displays a contextual menu when an item is control or right-clicked on since this behavior is often used in applications and if you're not using it, you probably could be! If you've never used a contextual menu before, you'll be amazed how simple it is to implement them. Begin by creating a new project with a listbox in the window and a contextual menu. The listbox should contain some default items like the example below does.
Contextual menus are used through 3 simple steps. The first, is when a mouse click occurs, check if the click was a contextual menu click (CMM click) using the global IsCMMClick() function. If IsCMMClick() returns true then either the click was a control-click or a right mouse button click and you'll need to display the menu by calling the contextual menu's Open() method. The Open() method synchronously displays the menu waiting for the user's choice until the next line of code executes. The last step is handling the user's choice which is done via the Action event which is fired when the user actually clicks on an item in the menu. If the user clicks outside of the bounds of the menu and in consequence does not select any menu item, then the Action event is not fired. The item As String paramter to the event is the text of the menu item's title which was chosen. Using a Select statement as below is usually the easiest way to handle the selection.
The code above will determine which menu item was chosen (MsgBox, Title, or Remove) and then take the appropriate action. Menu items are created just like popup menus:
To handle the click, we'll use the CellClick event of the listbox since it's the only event which lets know when a row is clicked on. We use the IsCMMClick() method as I said but notice that I also set the ListIndex of the list. The reason for this is that REALbasic doesn't update the ListIndex and redraw the row to show it is selected until after this event and all others (like the Change event) have been fired. To work around this, we force the change and an update.
That's it. Pretty simple eh? 11-19-03
Advanced Status System ElfData 2.0b4... free? HTMLField 2.11 P2Date 2.0 Days Away v1.2 SmartSplitter 1.2, SmartColorWell 1.0 SortLibrary 2.1 SQLitePlugin 1.3, SQLitePluginPro StringBuffer The Athenaeum Wastfield Plugin 2.1
|
|||
|
|