|
To access the contents, click the chapter and section titles.
Sams Teach Yourself Visual J++ 6 in 21 Days
Table 9.1 shows the fields in the DialogResult class that youll want to use as your dialog results.
Performing Tasks When Users ClickYou might want to perform certain tasks when users click a button. To handle these situations, select the button control. Go to its event list in the Properties window, and find the click event. Double-click on it. An event handler for the click event will be added, and it will open the source code to the newly added method. In the handler, you can add any code you need for handling the click event. If you want to close the dialog after youre done, just call the close() method. Bear in mind that the close() method will return a value of DialogResult.CANCEL. Useful Form MethodsVarious methods in the Form class can be useful for programming dialogs. Theyre also useful at other times. In this section, Ill mention and explain some of these. The getDisplayRect() method returns the display area used to display components on the Form. The area may be a virtual area if the Form is scrollable. The following example shows how to get the display rectangle for a Form: Rectangle rect; rect = getDisplayRect(); int nWidth = rect.width; int nHeight = rect.height; int nX = rect.x; int nY = rect.y; The getFormState() method returns bits associated with the specified form state. The bits that are returned are determined by the integer argument passed to the method. Table 9.2 shows the possible values.
The following example returns the value of 1 if there is a maximize button on the Form. It returns 0 if there isnt. int nValue; nValue = getFormState( FORMSTATE_MAXIMIZEBOX ); if( nValue == 1 ) { // Yes maximize box. } else { // No maximize box. } The getWindowState() method returns the current state of the window. The returned value equates to one of the enumeration constants defined in the FormWindowState class. Those values are shown in Table 9.3.
The following example gets the current state of the window: int nState; nState = getWindowState(); if( nState == FormWindowState.MAXIMIZED ) { // The Form window is maximized. } else if( nState == FormWindowState.MINIMIZED ) { // The Form window is minimized. } else if( nState == FormWindowState.NORMAL ) { // The Form window is in a normal state. } The pointToScreen() method converts a point in terms of the Form to coordinates in terms of the screen. The following example shows how its done: Point formPoint = new Point( 10, 10 ); // Form coordinate 10, 10 Point screenPoint = pointToScreen( formPoint ); // Now screenPoint has the converted coordinates. The setFormState() method sets elements of the Forms state. These elements are the ones that the getFormState() method deals with. (Refer to Table 9.2 for more information.) After you call the setFormState() method, the values returned in the getFormState() method will reflect the change. Any changes that result in visible changes to the window will be seen immediately. The following example removes the minimize box from the Form: setFormState( FORMSTATE_MINIMIZEBOX, false ); Almost every Windows programmer has at one time or another wanted to create a window that didnt place an item in the system taskbar. You can use the setShowInTaskBar() method to either allow or prevent a Form window from appearing in the system taskbar. The following example shows how to prevent the Form from appearing in the system taskbar: setShowInTaskBar( false );
|
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. |