Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!:Working With Text
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
Selecting Fonts Selecting fonts is the third place where our Baby Editor program will use the Common Dialog control. When used as a Font dialog box, the Common Dialog control has a Flags property you set to determine what is displayed in the dialog box. You must specify one of the following flags:
cdlCFPrinterFontsDisplays only printer fonts cdlCFScreenFontsDisplays only screen fonts cdlCFBOTHDisplays both screen and printer fonts
You can combine one of these flags with cdlCFEffects, which specifies that the Font dialog box should display underline, strikethrough, and color choices as well. Before displaying the Font dialog box, you should load it with the current font settingsthat is, the settings currently in effect in the Text Box control. You can accomplish this task easily by copying the relevant properties from one control to the other, before using the ShowFont method to display the font version of the Common Dialog control. When the user closes the dialog box, the program checks the FontName property of the Common Dialog. If this is a blank string, the user has canceled the dialog box, so we exit the procedure without making any changes to the Text Boxs Font property. Otherwise, we reverse the property-copying operation, making the Text Boxs font-related properties equal to the corresponding settings in the Font dialog box. The code for the Edit|Font commands Click event procedure is shown in Listing 11.15. The font selected applies immediately to all of the text in the editor. The font setting affects only the display, because font information is not saved in the file along with the text. Listing 11.15 The Edit|Font command event procedure.
Private Sub mnuEditFont_Click()
Set flags. CommonDialog1.Flags = cdlCFBoth Or cdlCFEffects
Set initial values for the dialog box. CommonDialog1.FontName = Text1.FontName CommonDialog1.FontSize = Text1.FontSize CommonDialog1.FontBold = Text1.FontBold CommonDialog1.FontItalic = Text1.FontItalic CommonDialog1.FontUnderline = Text1.FontUnderline CommonDialog1.FontStrikethru = Text1.FontStrikethru CommonDialog1.Color = Text1.ForeColor
Display Choose Font dialog box. CommonDialog1.ShowFont
If canceled, exit. If CommonDialog1.FontName = Then Exit Sub
Change the text font according to options selected. Text1.FontName = CommonDialog1.FontName Text1.FontSize = CommonDialog1.FontSize Text1.FontBold = CommonDialog1.FontBold Text1.FontItalic = CommonDialog1.FontItalic Text1.FontUnderline = CommonDialog1.FontUnderline Text1.FontStrikethru = CommonDialog1.FontStrikethru Text1.ForeColor = CommonDialog1.Color
End Sub
Exiting The Program To exit the program, we need only the End statement, placing it in the event procedure for the File|Exit command. To ensure that unsaved data is not lost, we call the SaveChanges function. After that, we either exit the sub procedure or end the program, depending on the return value of the function. The code for mnuFileExit_Click is shown in Listing 11.16. Listing 11.16 The File|Exit command event procedure.
Private Sub mnuFileExit_Click()
Verify that changes are saved, if user desires.
Dim Reply As Integer
Reply = SaveChanges() If Reply = False Then Exit Sub
End
End Sub
Thats it for the Baby Editorits all finished. Along the way, we have learned a lot about text processing, as well as about other aspects of Visual Basic, such as menus, functions, and file operations. I want to show you one more thing before closing this chapter.
Using Multiple Forms As I have mentioned several times previously, one of Visual Basics strong points is its ability to create and use software components. Its time to take a look at one way this is handled. Believe it or not, you have just created a software componentyour Baby Editor. The Calculator we built in a previous chapter is another component. A Visual Basic form, in other words, is one type of software component. How do you incorporate multiple forms in a project? Its really quite easy.
A project can have as many forms as needed. To add a form to an existing project, select Add Form from the Project menu. Then do either of the following:
To add a new, blank formClick on the New tab in the dialog box, click on the Form icon, then select Open. To add a form that already exists as part of another projectClick on the Existing tab and browse to locate the form file on disk.
When a project contains multiple forms, they will be listed in the Project Explorer window. To select one of these forms, click on its name, then click on either the View Object or View Code button (depending on whether you want to work on the forms controls or its code). No matter how many forms a project might have, only one can be shown first, when the program begins executing. This startup form is normally the first form created during project development. You can change the startup form by selecting Properties from the Project menu and clicking on the General tab in the dialog box that is displayed (Figure 11.6). Pull down the Startup Object list, and youll see a list of your projects forms. Select the one that is to be the startup form. How do you switch from one form to another? In other words, how do you control which of your projects forms are visible and which are not? Each Form object has a Show method that causes it to be displayed. The syntax is
FormName.Show style
where FormName is the forms Name property and style is an integer specifying the type of formmodal (style = 1) or modeless (style = 0 or style omitted). When a modal form is displayed, no keyboard or mouse input can occur for the application except to the modal form. This means the modal form must be hidden (usually in response to user action) before the user can activate or use any other form belonging to the same application. A modal form does not, however, prevent the user from activating or using another application. In contrast, a modeless form does not place these restrictions on the user. Display of a modeless form does not prevent the user from activating another of the programs forms. Thus, if a Visual Basic program has several forms displayed and one of them is modal, only the modal form will accept user input, even though the others are visible. If none of the forms is modal, the user can freely switch among them. Generally, you will use modeless forms unless you have a specific reason to use a modal form.
Figure 11.6 The General tab of the Project Properties dialog box.
To hide a form, use its Hide method. Note that using the Show and Hide methods has the same effect as setting the forms Visible property to True or False.