![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
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!
Other Menu Editor OptionsThe Menu Editor contains checkboxes for setting several menu item properties. These properties control how the menu item is displayed when the program is running and the user pulls down the menu:
You can also edit the structure of a menu as follows:
A few items in the Menu Editor remain to be covered. Ill let you explore them on your own. Programming The Editor, Part 2With the two controls placed and the menus designed, we have completed the visual design part of the Baby Editor project. Now we are ready to turn our attention to the code. Lets start with the general declarations section, which is where we place the declarations of global variables and constantsthose variables and constants that must be available in all of the modules procedures. We require two type Boolean flags, plus two type String variables. The general declarations code is shown in Listing 11.1. In case you dont remember how to display a specific part of a projects code, let me refresh your memory. If the Code Editing window is not open, click on the View Code button in the Project window. At the top of the window, use the Object list to select the object whose code you want to view (in this case, select General) and use the Proc list to select the specific procedure (in this case, Declarations). Listing 11.1 General declarations in BABYEDITOR.FRM. Option Explicit True if the text being edited has changed. Dim TextChanged As Boolean True if a file has just been loaded. Dim JustLoaded As Boolean Dim FileName As String, OldName As String Next, we will write the forms Form_Load event procedure, which is triggered when the form is first loaded. With a single-form program such as this one, the form is loaded when the program begins execution. That makes this procedure the ideal place for program initialization codecode that does things like initializing variables and object properties. We have two tasks for Form_Load : setting the two flag variables to False and setting the Common Dialog controls Filter property. I dont want to explain the details of this property setting here, because Ill be devoting a good deal of attention to the Common Dialog control later in the chapter. For now, try to restrain your curiosity. The code for the Form_Load procedure is presented in Listing 11.2. Listing 11.2 The Form_Load event procedure. Private Sub Form_Load() Dim Filter As String Clear flags. TextChanged = False JustLoaded = True Load filters into the common dialog box. Filter = Text files (*.txt) | *.txt Filter = Filter & |Batch files (*.bat) | *.bat Filter = Filter & |INI files (*.ini) | *.ini Filter = Filter & |All files (*.*) | *.* CommonDialog1.Filter = Filter End Sub The next procedure, Form_Resize, has the job of setting the size and position of the Text Box control to fill the form. The Form_Resize event procedure is triggered every time the forms size is changed, as well as when it is first displayed. The code for this procedure is shown in Listing 11.3. By setting the Text Boxs Top and Left properties to zero, it positions the Text Box against the top and left edges of the form. By setting the Text Boxs Width and Height properties to the values of the forms ScaleWidth and ScaleHeight properties, the Text Boxs size is made equal to the forms internal display area. Listing 11.3 The Form_Resize event procedure. Private Sub Form_Resize() Size the Text Box to fill the form. Text1.Top = 0 Text1.Left = 0 Text1.Width = ScaleWidth Text1.Height = ScaleHeight End Sub Note that a form object also has Width and Height properties, but these differ from ScaleWidth and ScaleHeight. The former two properties give the outer dimensions of an object; in the case of a form object, these dimensions include its border, title bar, etc. The ScaleHeight and ScaleWidth properties refer specifically to the forms display areathe area where you can place other objects. Youre probably wondering why we didnt specify an object for the ScaleWidth and ScaleHeight properties. Why didnt I write the code like this: Text1.Width = frmBabyEditor.ScaleWidth Text1.Height = frmBabyEditor.ScaleHeight In truth, I could have written it this way. The code would have worked fine; it just wasnt necessary. In an objects own event procedures, any reference to a property without an object name automatically refers to the objects own properties. If you run the project now, youll see that you can enter text into the Text Box. You can also select text using the standard methods: dragging with the mouse or holding Shift while using the cursor movement keys.
Implementing Cut, Copy, And PasteThe first requirement for the Cut, Copy, and Paste operations is taken care of for us by the Text Boxs built-in capabilities. As well soon see, so are most of the other parts. During program execution, the user can select text in the Text Box using the standard Windows techniques. The Text Box control has a property named SelLength that gives us the length (in characters) of the selected text in the Text Box, and another property named SelText that returns the selected text itself. Its a trivial matter to see if any text is selected (simply verify that SelLength is greater than zero) and, if so, to retrieve it.
|
![]() |
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. |