Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
One nice UI element that we can add to our application is to have the Rows that Display for the Tasks to have alternate color highlights, let's run the app so you can see what I mean. Right now everything is white, let's change it so that we'll have white gray between the lines, much like you see in say Apple's iTunes application. So let's go to our Todo Window and the way to do this is using an Event on the Listbox, so we'll go to our Task List Listbox and Double-click it, this switches us to the Code Editor, by default it jumps to the Method that has Code which is our Double-clicked Event. But the Event that we want to Add our Row Highlighting is the Cell Background Paint Event. This Event is Called as the Listbox is being drawn to the screen, essentially what we want to do is on every other row, paint the background of all the cells to be gray. Luckily we have some incoming parameters that are going to be useful here. In particular we have the Graphics Object which is where we will Draw the Background, and we know the Row and Column of the particular Cell that's being drawn. We want to do every column but only every other row so we're going to take the modulus of the row so that we only change the colors of the odd rows. Now in the Graphics Object we will Set the Foreground Color to be Equal to the Fill Color, this is a Constant built-into REALbasic, and then we will Draw a Filled Rectangle that fills the entire area of the particular cell we are working with and we can Save this and when we Run the Project you'll see that we now have alternating row colors. Very nice and Simple, but this Code we just put directly into the Task List if we wanted to reuse a Listbox that had this capability built-in to it we would Create a Subclass. So let's do that now, first we'll Add a Folder and we'll call it Controls, this is where we'll put our Subclass Controls and we'll Add a New Class which we'll call Listbox Control and we Set its Super to Listbox. When you Double-click it you'll see that it has all the same Events that we saw on the Todo Windows Task List Listbox, Cell Background Paint is the one we want. We can go get the Code from here and put it here. One thing to know when you are Creating a Control Subclass is by implementing the Event it no longer is accessible when it is dragged on a Window. Now that we've implemented the Cell Background Paint Event we can go back to the Todo Window and tell the task List that its Super is not Listbox but that its Super is actually Listbox Control, we can just click the arrow here and we'll see that it is now available for us to choose, and we can Save. And now when we Run we see the same behavior, there's no longer any code here for the Cell Background Paint Event. You'll notice that the Cell background Paint Event is completely missing and that is one thing to be aware of when you Create Subclass Controls, any Events that you implement on the Subclass or I should say on the Superclass will not appear on the Subclass as being a Subclass. But we can add them back, to do that we Add an Event Definition and we Mirror the Signature of the Event we just implemented. So we'll Add a New Event Definition and we'll call it Cell background Paint, we will make it a Function with the same parameters, here we have G As Graphics, Row As Integer, Column As Integer so let's Add that and this is a Function that returns a Boolean. And lastly we should Call this new Event with the parameters we've been given, now when we go back to the Todo Window you'll see that Cell Background Paint Event is back where it belongs and any code we put here will be executed because we are Calling it after we have done our Row Highlighting. Let's Run the Project and see that everything works as we expect.
| Course: | Real Studio |
| Author: | Paul Lefebvre |
| SKU: | 34190 |
| ISBN: | 1-936334-77-1 |
| Release Date: | 2011-02-02 |
| Duration: | 7 hrs / 87 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |