C ++ Builder First Learning and Answer (Nine)

zhaozj2021-02-16  42

9. Multi-page components

68) Q: I think that the management mode of the C Builder's component template is very good. You can switch between all pages in this template. How should I implement in C Builder?

A: We can use multiple page components to implement, it is the advantage of being allowed to store information as much as possible in a limited space, and it is easy to classify information. Take the component template, put hundreds of components in that small screen, and don't become messy, this is the credit of multi-page components.

If you place a large number of components on the form, and these components are used in grouping, then you can consider using multiple page components. Doing so can make the form more simply. Multi-page components have both multi-page features, and a container component, which can contain other components like forms.

C Builder provides several multi-page components that are: TabControl, PageControl components, Win31 pages in the Win32 page, TabbedNoteBook Components. From the different pages of their page, you can know that the first two components are components in the 32-bit system, regardless of performance or style, both components are more suitable for use in a board of Windows 95 or more. The latter components are preserved for users who love Windows 3.1 style, in fact, we can use only the first two components.

69) Q: TabControl components and PageControl components do they look like exactly?

A: At the beginning, the two components are indeed almost, we can explain this by the following operations.

(1) Place the two components on the form, set their size to the same size by modifying the Height and Width properties.

(2) In the Object Editor, click the omitial button in Tabs in TabControl's properties Tabs, and a string editor will pop up. Enter the first page, second and third pages in this editor. Then click the OK button.

(3) Select the PageControl component in the form, right-click the component, select the newpage command in the shortcut menu that pops up, the pageControl component will generate a page that is default "tabsheetn", where N starts from 1 Integer. The first time the new page command generated by TabSheet1, the second generated name TabSheet2, and so on. We use this command to generate three pages.

Unlike TabControl components, you can click on the page directly to switch the page. Click the page to switch the page while selecting the entire PageControl component. If you want to select a page, you can switch to the page first, then click the page.

(4) In the object editor, select TabSheet1, TabSheet2, and TabSheet3, modify it to the first page, the second and third pages, respectively.

This looks exactly the same.

70) Q: But if you have two different components, use one, don't you do, as if they don't really exactly?

A: You are right, don't be blinded by their appearance of the appearance, in fact they are different. TabControl is a "false" multi-page component, and PageControl is "true" multi-page component.

We know that the multi-page components put the information you want to display in different pages, and in fact, each page is a form and can switch by page. Although there are multiple pages, there are only one page template, that is, this page is updated according to the page template for each user, in order to respond to the user's selection. Obviously, if you need to display different components on each page, TabControl is definitely unable to compete with this job. Because you change the page each time you change the page, you must update the page template with the code, which is not a good way in C Builder. If the components displayed in each page are only changed, then TabControl will be more appropriate because it consumes less system resources.

PageControl is a page template per page. Therefore, it is suitable for different situations per page.

71) Q: What are the commonly used properties of TabControl components?

A: The hottrack property is used to determine if the label on the page is automatically lit. The default is false.

The multiline property is used to determine whether it is displayed when the page is displayed. The default value FALSE indicates that a two-way arrow appears in the right side of the row, which can be used to move the page.

The TabHeight property is used to set the height of the page. The default value 0 indicates the height of the page will automatically adapt to the height of the text on the page.

The TabWidth property is used to set the width of the page. The default value 0 indicates the width of the page to automatically adapt to the width of the text on the page.

When the TabPosition property is TPTOP, it means that the top of the TabControl component is represented by the top of TPTTOM.

Each page on the TabControl component has its own index. The index of the leftmost page is 0, the index of the page is 1, and so on. The TabINDEX property returns the page currently pressed.

Tabs properties are used to set the number of pages and their title, and a string editor is used when designing.

72) Q: What are the more important events in the TabControl control?

A: TabControl has two more important events onchange and onchanging. The onchange event will occur whenever the page is selected. At this time, it can be determined from the attribute TabINDEX to be selected, and then the action of the response will be taken.

The onchanging event just happens before the page is selected, that is, before switching to another page. This event allows us to take some actions before page switching, such as before certain conditions are not set, not allowed to leave this page.

In fact, these two events have previously been studied in detail, and they will no longer be explained here.

73) Q: PageControl component seems to be more powerful than TabControl component, how is it used?

A: Compared with TabControl, the features of the PageControl component are really large, but it is not complicated. Each page in PageControl is a TTABSHEET component, which is actually a container, you can place a variety of controls above. Each TTABSHEET component has its own properties.

In fact, there are two relationships here. The top of the top is the PageControl component, which is responsible for managing multiple TTABSHEET components, while each TTABSHEET component also manages components on it.

74) Q: What is important attributes in the PageControl component?

A: ActivePage This property displays the currently selected page, which can also be used to switch the page.

The multiline property is used to determine whether it is displayed when the page is displayed. The default value FALSE indicates that a two-way arrow appears in the right side of the row, which can be used to move the page. The default is false. The TabHeight property is used to set the height of the page. The default value 0 indicates the height of the page will automatically adapt to the height of the text on the page.

The TabWidth property is used to set the width of the page. The default value 0 indicates the width of the page to automatically adapt to the width of the text on the page.

When TabPosition This property is TPTOP, the page will be placed on top of the TabControl component, while the TPTOM will appear below.

In addition, there is a running timelination:

This read-only attribute is an array of all pages on the pageControl component.

PageCount This property returns the number of pages on the pageControl component.

75) Q: Every page of PageControl is a TTABSHEET component, what is the TTABSHEET?

A: TabVisible This property is used to block the display of a page. Also say, when its value is false, the PageControl component will not display this page, but this page still exists, you can also set this property to true to restore its display. You cannot delete the page during the program run, and only the display of the page can be shielded.

PageIndex is the index number of the page,

In addition, there are running timeliness properties.

The pageControl property returns the PageControl component where the page is located.

TabINDEX Properties Returns the index number in all visible pages.

Because the page cannot be deleted at the time of the program, the PageIndex index number is fixed. But the page can be blocked. When there is no page being blocked, TabINDEX is exactly the same as PageIndex; TabINDEX is different from pageIndex when a page is blocked. TabINDEX is this page in all visible pages, that is, the first visible page TabINDEX is 0, the second visible page TabINDEX is 1, and so on.

76) Q: Can I design an example to make me better understand them?

A: Ok, first place an edit box component on the page of TabControl components.

Then place an edit box assembly in the TAB1 page of the PageControl component.

The PageControl component is then switched to the TAB2 page, and a text edit box component is placed.

Finally, compile and run this program.

Click on the Tab1 to Tab3 tab of the TabControl component, you can see that the edit box appears in each page of the component.

Click

PageControl

Component

Tab1

Until

Tab3

Tags, you can see that each component is different.

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

New Post(0)