|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
Setting A Forms Startup PositionYou can set the position of a form when it is first displayed by positioning it in the Visual Basic IDEs forms window, or by setting the StartUpPosition property at design time (this property is not available at runtime):
Note, of course, that you can also position a form in the forms Load event handler by setting its Left and Top properties. Keeping A Forms Icon Out Of The Windows 95 TaskbarThe Aesthetic Design Department is on the phone again. The dialog boxes in your program, SuperDuperTextPro, are fine, but theres one little problem: when you display a dialog box, its icon appears in the Windows 95 taskbar, and according to company specs, dialog boxes should not add an icon to the taskbar, even when theyre displayed. Oh, you say. Its easy to keep a dialog boxs iconor other forms iconout of the Windows 95 taskbar; just set that forms ShowInTaskbar property to False at design time (this property is read-only at runtime). In fact, thats the most common use for this propertyto keep dialog box icons out of the taskbar. Handling Keystrokes In A Form Before Controls Read ThemTheres a subtle war for possession of the focus between forms and controls in Visual Basic. If you click a form, giving the focus to that form, what really happens is that a control in that form (if there are any) gets the focus. But what if you really wanted to give the focus to the form as a whole to use the forms keystroke events? It turns out that you can indeed make sure the form gets keystrokes even before the control with the focus gets them by setting the forms KeyPreview property to True (the default is False). You can set this property at runtime or design time. Lets see an example. Here, we add a text box, Text1, to a form. When the users click the form, well start intercepting keystrokes before they go to the text box. Following the Christmas example developed earlier in this book, well remove all occurrences of the letter L when the user types that letter (making the text box a No-L text box). Heres how we start intercepting keystrokes when the user clicks the form:
Private Sub Form_Click()
KeyPreview = True
End Sub
Now well get the keystrokes first, as the user presses them, no matter what control has the focus. We can remove the letter L before its passed on to the text box in our example this way:
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc("L") Then
KeyAscii = 0
End If
End Sub
Making A Form ImmovableThe Aesthetic Design Department is calling. They like the screen position theyve set for the windows in your programis there any way to make sure the user cant move them? There is. You can set the forms Moveable property to False. Note, however, that you can only set this property at design time. Showing Modal FormsThe Testing Department is on the phone again. When you show that form full of options, you shouldnt let users go back to the main form until theyve chosen the options they want. Hmm, you think, how does that work? You can make a form modal, which means that the user has to dismiss it from the screen before working with the other forms in your application. You usually make only dialog boxes modal, but you can make any form modal if you wish. To make a form modal, pass the constant vbModal to the Show method:
Private Sub Command1_Click()
Form2.Show vbModal
End Sub
Saving Values In The Windows RegistryPlacing data in the Windows Registry saves that data for the next time your program runs, and the kind of data you save there usually represents settings for your program, such as window size and location. You can use the Windows Registry directly from Visual Basic. To save a setting in the Windows Registry, you use the SaveSetting statement: SaveSetting appname, section, key, setting Here are the arguments for SaveSetting:
Heres how it works: to save a setting in the Windows Registry, you pass your applications name, a section name, a key name, and the setting for that key. Using section names allows you to break up an applications set of keys into different groups, which can be handy in terms of organization. Those keys are the actual variables that you save settings to. Well see an example showing how to get and save settings with the Windows Registry in the next topic. Getting Values From The Windows RegistryYou can get settings that youve placed in the Windows Registry with the GetSetting function, which returns the value of that setting, or the default value as specified in the list that follows: GetSetting( appname, section, key[, default]) Here are the arguments passed to this function:
Lets see an example. In Chapter 5, we developed the MRU application, which supports a Most Recently Used (MRU) menu item in the File menu. This item displayed the most recently opened files name using data stored in the Registry.
|
|
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. |