Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:ActiveX Controls
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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!
(Publisher: The Coriolis Group)
Author(s): Peter G. Aitken
ISBN: 1576102815
Publication Date: 08/01/98
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Here are the steps to follow:
1. Open the FancyCmdButton designer, and then open its Code window.
2. Select Add Procedure from the Tools menu to display the Insert Procedure dialog box.
3. Specify the procedure name Caption, and select the Property and Public options. Then click on OK.
4. Visual Basic will create skeletons of the Let and Get procedures for you, displaying them in the Code Editing window. Add the code shown in Listing 17.6. Be sure to change the type of the Get procedure from Variant to String. Make the same change for the type of the argument to the Let procedure. Remember that the Get procedures return type must be the same as the type of the Let procedures argument.
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.
Figure 17.8 ActiveX control properties that you define are listed in the Visual Basic Properties window along with the default properties.
Adding A Property Page To The Control
You 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.
Figure 17.9 After adding a property page, a blank property page is displayed.
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.
Figure 17.10 The property page after placing its two controls.
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
Previous
Table of Contents
Next
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.
Wyszukiwarka
Podobne podstrony:
Ochrona własności intelektualnej MBM 2 TOK Wtorek TN 17 05From NY 3 17 05 Sauter FM 144064 X2 mbw 05 01 17 praTI 00 05 17 T B pl(1)TI 01 05 17 T B pl(2)więcej podobnych podstron