⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch06.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
</UL><H4>Selecting Individual Components</H4><P>To select a single component, just click on it. When you select the component,eight black sizing handles appear around the component to indicate that it is selected.(I'll discuss the sizing handles in a moment.) Figure 6.1 shows a form with a buttoncomponent selected.</P><P>As soon as you select a component, the Object Inspector changes to show the propertiesand events for the control you selected. To deselect a control, click on the form'sbackground or Shift+click on the control. (Shift+click is described in the next section.)</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> Each component has a default event handler associated with it. When	you double-click a component on a form, the Code Editor displays the default event	handler for that component, ready for you to type code. In most cases, the default	event handler is the OnClick handler. Exactly what happens when the component is	double-clicked depends on how the component is designed. For example, in the case	of the Image component, double-clicking will display the Picture Editor dialog box.	<HR></BLOCKQUOTE><P><A HREF="javascript:popUp('28670601.gif')"><B>FIGURE 6.1.</B></A><B> </B><I>Aform with a button component selected.</I></P><P><H4><BR>Selecting a Group of Components</H4><P>You can also select multiple components so that you can act on them as a group.This is accomplished in one of three ways:</P><UL>	<LI>Shift+click with the keyboard and mouse.	<P>	<LI>Drag with the mouse.	<P>	<LI>Choose Edit | Select All from the main menu.</UL><P>To select all components on the form, choose Edit | Select All from the main menu.</P><P><H4>Selecting Components with Shift+Click</H4><P>To use the Shift+click sequence, first select one control. Then press and holdthe Shift key on the keyboard and click on any other controls you want to includein the selection. Each control you click is bounded by four gray boxes to indicatethat it is part of the selection.</P><P>You can remove a control from the selection by continuing to hold the Shift keyand again clicking on the component. In other words, the Shift+click sequence togglesa component's inclusion in the selection. To illustrate, first start with a blankform and then perform the following steps:</P><DL>	<DT></DT>	<DD><B>1. </B>Place three button components anywhere on the form. They will automatically	be labeled Button1, Button2, and Button3.	<P>	<DT></DT>	<DD><B>2. </B>Click Button1. The black sizing rectangles appear around the component.	<P>	<DT></DT>	<DD><B>3. </B>Press and hold the Shift key on the keyboard. Click Button2. It is	added to the selection. Gray boxes now appear at the corners of both Button1 and	Button2.	<P>	<DT></DT>	<DD><B>4. </B>Shift+click on Button3. Now all three buttons are part of the selection.	<P>	<DT></DT>	<DD><B>5. </B>Shift+click again on Button2. Button2 is removed from the selection	(the gray boxes disappear), but Button1 and Button3 are still included in the selection.	<P>	<DT></DT>	<DD><B>6. </B>Shift+click on Button1. Now Button3 is the only component in the selection.	The gray boxes are replaced with the black sizing rectangles.	<P>	<DT></DT>	<DD><B>7. </B>Shift+click on Button1 and Button2. All three buttons are now part	of the selection again.	<P></DL><P>Figure 6.2 shows the form as it will look at the end of this sequence. Keep inmind that your buttons could have been placed anywhere on the form. Keep the formhandy because you'll use it again in the next exercise.</P><P><A HREF="javascript:popUp('28670602.gif')"><B>FIGURE 6.2.</B></A><B> </B><I>Aform with three buttons selected.</I></P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> If you click on a component that is part of a selection, nothing	will happen. To select a single control that is currently part of a group selection,	you need to first click on the form's background or press the Esc key to remove the	group selection. Then you can click on the individual control you want to select.	<HR></BLOCKQUOTE><H4><BR>Selecting Multiple Components by Dragging</H4><P>You can select multiple controls by dragging a bounding rectangle around the controlsto be selected. The <I>bounding rectangle</I> is a broken-line rectangle that changessize as you drag. In fact, you don't have to drag the bounding rectangle completelyaround the components. You have only to touch a component with the bounding rectanglein order for it to be included in the selection.</P><P>Be sure that you start by placing the mouse cursor over the form's backgroundand not on a component. Hold the left mouse button down and begin dragging. You willsee the bounding rectangle as you drag. Surround or touch the components you wantselected and release the mouse button. Any components that were inside the boundingrectangle (or touching it) are included in the selection.</P><P>When you have selected a group of controls, you can use the Shift+click techniqueexplained in the previous section to add other controls to the selection or to removecontrols from the selection. For example, you might want to select all controls inone area of your form except for one. Surround the controls and then deselect thecontrol you want to exclude from the selection.</P><P>Go back to the form with the three buttons you created earlier (if you've alreadydiscarded that form, create a new one and place three buttons on it). Start at thetop-left corner and drag down and to the right to surround the buttons. Let go ofthe mouse button and the controls will be selected. Figure 6.3 shows the form andthe bounding rectangle being dragged.</P><P><A HREF="javascript:popUp('28670603.gif')"><B>FIGURE 6.3.</B></A><B> </B><I>Controlsbeing selected by dragging.</I></P><P><strong>CAUTION:</strong> You can use Shift+drag to select non-adjacent groups of controls.If, for instance, you have two separate groups of controls in different areas onyour form, you can drag around the first set and then hold the Shift key down anddrag around the second set. Both groups will be selected.</P><BLOCKQUOTE>	<P><HR><BR>	<strong>NOTE:</strong> You don't have to drag down and to the right. You can drag in any	direction to select components. <HR></BLOCKQUOTE><H4><BR>Selecting Multiple Items: Components within Components</H4><P>Frequently you will have components placed within other components. The Panelcomponent is often used as a container for other components. To select a group ofcomponents on a panel, you have to hold down the Ctrl key on the keyboard while youdrag to select the components. (Try it without holding down the Ctrl key and seewhat happens!) In case you're wondering, yes, you can use a combination of Ctrl+Shift+drag.(I suppose the Borland designers could have figured out some way of working the Altkey in there, too.)</P><P>To illustrate, first start with a blank form. Then do the following:</P><DL>	<DT></DT>	<DD><B>1. </B>Select a Panel component from the Component palette and place it on	the form using the drag method. Drag it so that it occupies most of the form.	<P>	<DT></DT>	<DD><B>2. </B>Now select a Button component and place six buttons on the form. Your	form will look something like Figure 6.4.	<P></DL><P><A HREF="javascript:popUp('28670604.gif')"><B>FIGURE 6.4.</B></A><B> </B><I>Theform with a panel and six buttons.</I></P><DL>	<DT><I></I></DT>	<P>	<DT><I></I></DT>	<DD><B>3. </B>Drag a bounding rectangle around Button1, Button2, and Button3. Notice	that you moved the panel, which is not what you expected (and not what you wanted).	Move the panel back to where it was.	<P>	<DT></DT>	<DD><B>4. </B>Hold down the Ctrl key and drag a rectangle around Button1, Button2,	and Button3. The buttons are selected.	<P>	<DT></DT>	<DD><B>5. </B>Now hold down both the Ctrl and Shift keys and drag the bounding rectangle	around Button5 and Button6. Now all buttons are selected except Button4.	<P></DL><P>Using the Ctrl+drag sequence is the only way to select a group of components containedwithin another component if you are using the drag method. You can use the Shift+clickmethod to select components contained within another component just as you do whenselecting components on a form.</P><P><H3><A NAME="Heading6"></A>Moving Components</H3><P>Moving components is a common and simple task. To move an individual component,place the mouse cursor over the component and drag. As you drag, a rectangle thatrepresents the component moves with the mouse cursor. When you have the rectanglewhere you want it, let go of the mouse button and the component will be moved tothat location.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> When you move a control via drag and drop, the control's Left and	Top properties are automatically updated. If you pause for a moment while moving	a component, you will notice a tooltip appear next to the mouse cursor. The tooltip	shows what the new top and left position of the component will be when you stop dragging.	<HR></P>	<P><HR>A similar tooltip is displayed when sizing a component by dragging. In the case of	sizing a component, the tooltip shows what the new width and height of the component	will be when you stop dragging. Figure 6.6 shows the tooltip you see when sizing	a component (in the lower-right corner). <HR></BLOCKQUOTE><P>If you have the Snap to Grid option on, the dragging rectangle will snap to thenearest grid point as you drag.</P><BLOCKQUOTE>	<P><HR><strong>TIP:</strong> If you change your mind while dragging, you can press the Esc key	on the keyboard before you release the mouse button to cancel the drag operation.	The component will return to its original position. <HR></BLOCKQUOTE><P>Dragging a group of controls works the same way. After you have a group of componentsselected, place the mouse cursor over any one of the controls and begin dragging.The dragging rectangle will be displayed for each control in the group. This enablesyou to visualize where the group will be placed when you release the mouse button.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> You cannot move a group of components if components in the group	have different parent controls. For instance, let's say you select both a Button	component on the main form and a SpeedButton on a panel. Because these two components	have different parent controls, you cannot move them as a group. <HR></P>	<P><HR><BR>	<strong>TIP:</strong> When you have selected a control, you can nudge it a pixel at a time	by holding down the Ctrl key while using the arrow keys on the keyboard. This technique	works for both groups of controls and individual controls. The Snap to Grid feature	is overridden when you use this technique.<BR>	After you have moved a component using this method, the component is no longer on	a grid point--it is offset by some amount. If you now drag the component, it will	maintain its offset from the grid point as you drag.<BR>	<strong>TIP:</strong> If you move a control using the Ctrl+arrow method and want to align	it again to the grid, choose Edit | Align to Grid from the main menu. The control's	top-left corner will snap to the nearest grid point. <HR></BLOCKQUOTE><P>A control cannot be dragged outside its parent form. If you drag a component offthe form's left or top edge, you will see that the component is clipped at the form'sedge. If, however, you drag the component off the right or bottom of the form anddrop it, scrollbars will appear on the form so that you can scroll to see the restof the form.</P><P>The form's Width and Height properties are not altered. If you drag the componentback onto the visible part of the form, the scrollbars disappear again. This is thedefault behavior and will occur unless you change the form's AutoScroll propertyto False. Figure 6.5 shows a Memo component that has been dragged partially off theform's right edge. Notice the scrollbar that appears at the bottom of the form.</P><P><H3><A NAME="Heading7"></A>Preventing Components from Being Moved or Sized</H3><P>Components can be locked into place so that they cannot be moved. Locking componentsis useful if you know that a form's design is final and you don't want to worry aboutaccidentally moving controls. To lock a form's controls, choose Edit | Lock Controlsfrom the main menu. Locked controls cannot be moved or sized. When controls are locked,their sizing handles are gray with a black border. To unlock the controls, chooseEdit | Lock Controls again. The controls can now be moved as before. You can lockall components on a form with this technique or none of the components. You cannot,however, lock just selected components.</P><P><A HREF="javascript:popUp('28670605.gif')"><B>FIGURE 6.5.</B></A><B> </B><I>Aform with AutoScroll in action.</I></P><P><H3><A NAME="Heading8"></A>Ordering, Cutting, Copying, and Pasting Components</H3><P>Sometimes you will place components on top of one another to achieve a visualeffect. For example, a shadowed box can be created by placing a white box over ablack box (both would be Shape components). Obviously you can't have the shadow ontop of the box, so you have to order the controls to tell Delphi which controls goon top and which go on the bottom. Let's do a simple exercise that illustrates this.Along the way, you will also see how you can use Copy and Paste with components.First, start with a blank form (you know the drill by now). Now follow these steps:</P><DL>	<DT></DT>	<DD><B>1. </B>Click on the Additional tab on the Component palette and choose the	Shape component. Click on the form to place the shape. A white square appears on	the form.	<P>	<DT></DT>	<DD><B>2. </B>Size the shape as desired (mine ended up being 209 pixels by 129 pixels).	<P>	<DT></DT>	<DD><B>3. </B>Be sure the Shape component is selected. Choose Edit | Copy from the	main menu.	<P>	<DT></DT>	<DD><B>4. </B>Choose Edit | Paste from the main menu. A copy of the shape is placed	below and to the right of the original shape. Conveniently, this is exactly where	you want it.	<P>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -