C ++ Builder first-study and answer (12)

zhaozj2021-02-16  46

(This series of articles is only available for 9CBS, and also authorized ccrun reprinted, other individuals are not reproduced, extracted, if you need to use, please contact the author or 9CBS)

13. Dialog Box Components

96) Q: How to write files, save, etc. dialog box?

A: C Builder provides us with many commonly used dialog assemblies, which are placed in the Dialogs tab of the Component Template, such as Font, Color, Open, and Print dialogs. Where the OpenDialog dialog assembly is most representative, as long as it has the usage, you will use other dialog assemblies.

97) Q: What are the characteristics of the characteristics of the dialog assembly?

A: The dialog assembly is an invisible component. When you put it on the form, it is a size and unchanging graphic button. When the program runs, the dialog assembly will not display immediately, but must use the Execute method with each dialog box to make the dialog box. show.

Most of the dialog provided by C Builder is a mode dialog. This dialog requires first, you must respond to the dialog, and then continue working. The so-called response dialog is that you must click OK or Cancel button to return a dialog to a value. When the user clicks OK on the dialog, returns true, click the CANCEL button to return false. The user can perform different processing according to the different returns.

Non-mode dialogs allow you to complete other work before responding to dialog boxes, do not have to respond to dialogs first. Such dialogs are: FindIalog, ReplaceDialog, etc.

98) Q: Do you have more ways to dialog box components?

A: We prepare a text reader to explain how to use the file open dialog.

Open a new form, we put a button component and a MEMO component, set the MEMO's scrollbars property to SSBoth, so that MEMO can display vertical and horizontal scroll bars.

Check the Lines property and delete the text inside.

Place the OpenDialog component on the form.

Select the OpenDialog component, you can see that OpenDialog has some main features.

The FILRERINDEX property is used to specify the default filter used by the dialog per open dialog.

The DEFAULTEXT property is an extension that the dialog box uses it as the default extension when the file name entered in the file editing box does not have an extension.

The initialdir property is used to set the directory displayed when the dialog is opened.

The FileName property is used to return the full path name of the most recently selected file.

Filter properties, this property is used to design which types of files will be listed in the file list of dialogs.

The OpenDialog dialog box provides a dedicated editor to edit the properties Filter, click the editor to open this editor in the omitted button in the Value column of the property Filter.

The left side is used to enter the name of the filter, and the right side is used to enter the file extension.

Now, we enter the filter of the text file and the C file. In this way, the name of the filter will be displayed in the file type drop-down list when the dialog is opened each time.

Double-click the open button, enter such a code:

/ / -------------------------------------------------------------------------------------------- ---------------------------

#include

#pragma HDRSTOP

#include "unit1.h"

/ / -------------------------------------------------------------------------------------------- --------------------------- # prgma package (smart_init)

#pragma resource "* .dfm"

TFORM1 * FORM1;

/ / -------------------------------------------------------------------------------------------- ---------------------------

__fastcall tform1 :: tform1 (tComponent * Owner)

: TFORM (OWNER)

{

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

Void __fastcall tform1 :: button1click (Tobject * Sender)

{

IF (OpenDialog1-> execute ()) // Firstly, the Open File dialog function is performed, at this time, the open file dialog is displayed. If the execution is successful, this function returns True, otherwise returns false

{

Memo1-> lines-> clean (); // clear the content in MEMO

CAPTION = Opendialog1-> filename; // obtain the path name of the user selected, and set it into a form of the form. Note that because it is in the Form1 window (container), it saves FORM1 before capen, of course you can add

Memo1-> Lines-> LoadFromFile (OpenDialog1-> filename); // Call text installation function to load text from the file and display in the edit box

}

}

/ / -------------------------------------------------------------------------------------------- ---------------------------

99) Q: What are the important properties of other dialogs?

A: Save dialog Savedialog is very similar to the open dialog, as for OpenPictureDialog, SavePictureDialog doesn't have to say more. Other image font dialog fontdialog's font attribute; color dialog colordialog's Color property; lookup dialog FindDialog's FindText. You don't have to say more here, look at it.

100) Q: Do you only use those components mentioned above? If you have, can you introduce it?

A: In the visual component of the C Builder integrated development environment, the application developer provides a series of standard dialog functions. We can call these functions directly to display some standard dialogs.

This type of function is still a lot, but we only need to master the following five, it is enough.

Extern package int _fastCall Messagedlg (Const Ansigntring MSG, TMSGDLGTYPE DLGTYPE, TMSGDLGBUTTONS Buttons, int helpctX): Used to display dialogs in the center of your computer screen.

Where parameter MSG is a string that specifies the displayed in the To dialog.

Parameter DLGTYPE is a variable of the TMSGDLGTYPE class that is used to specify the display feature of the dialog. TMSGDLGTYPE is a collection that can take the following values:

MtWarning: The dialog box contains yellow horizons;

MTERROR: The dialog box contains red horizons;

The Mtinformation: The dialog box contains the blue "i" symbol; MTConfirmation: The dialog box contains green question mark;

MTCUSTOM: The bitmap symbol is not included in the dialog, the title name is the application name.

The parameter button is used to specify the type of button contained in the dialog, which is a collection, which can be a combination of several elements:

MBYES: The dialog contains the "YES" button;

MBNO: The dialog contains the "NO" button;

Mbok: The dialog contains the "OK" button;

MbCancel: The dialog contains the "Cancel" button;

Mbabort: The dialog contains the "ABORT" button;

Mbretry: The dialog contains the "Retry" button;

Mbignore: The dialog contains the "IGNORE" button;

MBall: The dialog contains the "all" button;

MBNOTOALL: The dialog contains the "NOTOALL" button;

Mbystoall: The dialog contains the "YESTOALL" button;

Mbhelp: The dialog contains the "Help" button.

C Builder also specifically defines three common buttons combinations:

MBYESNOCANCEL: contains Mbyes, MBNO, and Mbcancel elements;

MbokCancel: The Mbok and Mbcancel elements are included;

MbabortRetryIgnore: The Mbabort, Mbretry, and Mbignore elements are included.

Parameters HelpctX is used to specify that when the user selects help, the context number in the system helps the system. This function will return the corresponding value according to the button selected, which have the following return values: mrnone, MRabort, MROK, MRRETRY, MRNO, MRCANCEL, MRIGNORE, MRALL.

EXTERN PACKAGE VOID _FASTCALL SHOWMESSAGE (Const Ansistring MSG): This function is used to display a dialog box that contains a "OK" button. The content displayed in the dialog is determined by the parameter MSG.

EXTERN PACKAGE ANSISTRING _FASTCALL INPUTBOX (Const ASISTRING ACAPTION, CONST ANSISTRING APROMPT, Const ASISTRING APROMPT): This function is used to display a dialog on the computer screen, this dialog has a text edit box, which can be used to receive the string input by the user information.

Acaption: The title used to specify the dialog;

APROMPT: The content used to specify the content displayed in the dialog;

Adefault: The content used to specify the content displayed in the edit box when the dialog is turned on.

EXTERN PACKAGE BOOL (Const ASSTRING ACAPTION, ANSISTRING & AUSERNAME, ANSISTRING & AUSERNAME): This function is used to display a standard login dialog for connecting a database server, and its parameters are the name of the database in the dialog, user input user name and password.

extern PACKAGE bool _fastcall SelectDirectory (const AnsiString Caption, const WideString Root, AnsiString & Directory) or extern PACKAGE bool _fastcall SelectDirectory (AnsiString & Directory, TselectDirOpts Options, int HelpCtx): This function allows the user to display a dialog box, enter the directory name. Where: The first grammar is used to specify the title of the dialog; root is used to specify which root directory starts to browse; parameter DIRCETORY is used to determine the user selected directory. This syntax cannot change the current directory.

The second syntax parameter options are a collection that can be combined by several elements:

SDALLLOWCREATE: Allows users to enter a nameless directory name, but do not create this new directory;

SDPERFORMCREATE: It must be used with SDALLOWCREATE, and when the user enters an unsatisfactory directory name, the dialog will create this directory;

SDPROMPT: It must be used with SDALLLOWCREATE. When the user enters a direct directory name, the message dialog box will appear, ask the user to create this new directory. If the user selection is, this new directory will be created when including the SDPERFORMCREATE element, and if there is no SDPERFORMCREATE element, the directory will not be created.

"Foundation Getting Started" 100 Ask this, this is over, because the original is written in Word, sometimes there will be some errors when it is here, thereby bringing a lot of unnecessary labor, so thank you for your editor. hard work! J

Note: All routines this article are compiled under the XP system, BCB6.

(Full text is not over)

转载请注明原文地址:https://www.9cbs.com/read-26006.html

New Post(0)