![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
Here are the steps to follow:
Listing 17.6 Get and Let procedures for the Caption property. Public Property Get Caption() As String Caption = lblButton.Caption End Property Public Property Let Caption(ByVal vNewValue As String) lblButton.Caption = vNewValue End Property Once you have added this code, close the ActiveX designer to put the FancyButtonControl in run mode. Display the test form with the FancyCmdButton on it and click on the button to select it. Look in the Properties window (refer to Figure 17.8), and youll see that the controls property list now includes a Caption propertythe one you just definedin addition to the UserControls default properties. If you change this property during design, the text you specify will be displayed on the FancyCmdButton when the test project runs. You could also set the property in code. To try this out, place the following line of code in the test projects Form_Load procedure: FCB1.Caption = Click Me Youll see that the button displays Click Me when the program runs.
Adding A Property Page To The ControlYou have already seen that the ActiveX control properties you define are automatically displayed in the Visual Basic Properties window. You also have the option of connecting a property page to the control. A property page is simply a different method of displaying and accessing the controls properties. Each property page you define will become a separate tab in the objects Properties dialog box. You must design the page, which is done in much the same way as designing a Visual Basic form. Visual Basic takes care of all the details of displaying the tabs, and managing the OK, Cancel, and Apply buttons. Property pages are useful when several properties interact in a complex fashion. You can design the property page so that related properties are grouped together, making it easier for the user to set them properly. Property pages are useful for controls that you plan to distribute internationally, because the captions on the property page can easily be changed to suit different language requirements. Finally, property pages permit controls to be used with development tools that dont have Properties windows. To add a property page to the FancyCmdButton, click on AXCtrlDemo in the Project window to make the control project current. Then, select Add Property Page from the Project menu. In the next dialog box, select the Property Page icon. (If you like, you can explore the other optionthe Visual Basic Property Page wizardon your own.) Visual Basic adds a property page to the project, as shown in Figure 17.9. The Property Page form is displayed, and its properties are listed in the Properties window. Note that the Visual Basic title bar indicates that the Property Page designer is active by displaying [PropertyPage1 (PropertyPage)]. Note also that a Property Page entry has been added to the listing in the Project window.
In the Properties window, change the property pages Name property to FCBGeneral and the Caption property to General. The caption will be displayed as the tab title in the Properties dialog box; the name identifies it as the FancyCmdButtons General property tab. Select Save from the File menu and save the property page under the suggested name, which is the same as the Name property you just assigned (FCBGeneral). Visual Basic automatically adds the .PAG extension to property page files. The next task is to design the property page itself, placing controls on it to permit the user to read and set the controls properties. Because the FancyCmdButton control has only a single property, Caption, this will be a quick task. Designing a property page is essentially the same as designing a regular Visual Basic form: drag and drop controls and so on. Start by placing a Label control on the property page. Set the Labels Caption property to Caption. Place a Text Box control under the Label, and set its Text property to a blank string and its Name property to txtCaption. At this point, your property page will look like Figure 17.10. The property page interacts with the control it is attached to by using events. Whenever a property page is opened, it receives a SelectionChanged event. It receives the same event if and when the user changes the controls that are selected on the current form (remember, the property page will be used when the user is designing a form and has placed one of your controls on it). Our task is complicated by the fact that the user can select more than one controlit is perfectly possible for a user to place two or more FancyCmdButton controls on a form and select all of them. Because a property page is modeless, the user can change the selected controls while the property page remains open.
Basically, you have two options for dealing with multiple selected controls. The one you use will depend on the nature of the specific property. For some properties, such as ForeColor, it makes sense to permit the user to change the property setting for two or more controls at once. Note that I am using ForeColor as a generic exampleit is not a property of our FancyCmdButton control. In contrast, other properties are not appropriate for such batch changes; if multiple controls are selected, you want to disable that property. The Caption property of our demonstration control falls into the latter category. Dealing with the possibility of multiple selected controls is simplified by the SelectedControls collection, which provides a zero-based index list of the control(s) that are currently selected on the form. You can query this collections Count property to see if more than one control is selected, then take the appropriate action. For the single property on the FancyCmdButtons property page, use the code shown in Listing 17.7. This code is placed in the property pages SelectionChanged event procedure. Listing 17.7 The property pages SelectionChanged event procedure. Private Sub PropertyPage_SelectionChanged() Enable the Text Box for the Caption property only if there is a single control selected. If SelectedControls.Count = 1 Then txtCaption.Enabled = True Display the current property value on the property page. txtCaption.Text = SelectedControls(0).Caption Else txtCaption.Enabled = False End If End Sub
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |