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

📄 ch13.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
end up losing definition and don't look quite right.) This happens with buttons thatdon't have enough contrasting colors. In that case, you can create a second imagelist that contains the disabled button glyphs. Set the DisabledImages property ofthe toolbar to the image list containing the disabled glyphs, and the rest is automatic.For ScratchPad you're going to go with the automatic disabling of toolbar buttons,so nothing further is required.</P><P>Poor old ScratchPad is back together again. This is a good time to save the project.After saving the project, click the Run button and give the program a workout. Clickthe buttons and see whether they do what they are supposed to do. If all went well,you have a working program again. If your program won't compile, review the stepsand try to fix the problem. If all else fails, you can refer to the ScratchPad projectof the book's code, available at http://www.mcp.com/info (Day 13).</P><P><H4>Toolbar Tips and Hints</H4><P>I covered nearly everything there is to be said about tooltips and hints in thediscussion of components on Day 7, &quot;VCL Components&quot;; again on Day 8, &quot;CreatingApplications in Delphi,&quot; when adding hint text support for the ScratchPad program;and again today when rebuilding the toolbar.</P><P>There is one issue I didn't talk about, and that is changing the tooltip properties.The TApplication class has four properties that control how the tooltips behave.Table 13.1 lists these properties and their descriptions.</P><P><H4>TABLE 13.1. TApplication PROPERTIES PERTAINING TO TOOLTIPS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Property</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Hintcolor</TD>		<TD ALIGN="LEFT">Sets the background color of the Tooltip window. Default: CLINFOBK</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">HintHidePause</TD>		<TD ALIGN="LEFT">Controls how long to wait (in milliseconds) before hiding the tooltip if the mouse			cursor remains stationary over the component. Default: 2500 milliseconds</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">HintPause</TD>		<TD ALIGN="LEFT">Controls the interval between the time the mouse cursor is paused over a component			and the time the tooltip appears (in milliseconds). Default: 500 milliseconds</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">HintShortPause</TD>		<TD ALIGN="LEFT">Controls how long to wait before showing tooltips after they have already been shown--for			example, when the user is roaming over a group of toolbar buttons. Default: 50 milliseconds</TD>	</TR></TABLE></P><P>The default values for these properties are sufficient for most applications.Still, if you need to change any hint properties, you have that option.</P><BLOCKQUOTE>	<P><HR><B>HOUSE RULES: TOOLBARS AND HINTS</B></P>	<UL>	<LI>Don't use tooltips on controls where they will be in the way when the user wants	to read the text in the control. In particular, don't use tooltips for edit controls	and combo boxes. At a minimum, give the user the option to turn off tooltips for	those types of controls.	<P>	<LI>Keep your tooltip hint (the short hint) brief and to the point.	<P>	<LI>Make your status bar hint (the long hint) more descriptive and meaningful.	<P>	<LI>Consider giving your users the option of turning off hints altogether.	</UL>	<P><HR></BLOCKQUOTE><H4>Adding Other Controls to Toolbars</H4><P>Because the ToolBar component is so versatile, nothing special needs to be doneto add other types of controls to your toolbar. The most common type of control toadd to a toolbar is a combo box. You can use a toolbar combo box to select a font,a configuration option, a zoom setting. . . the possibilities are endless.</P><P>To add a component to the toolbar, select the component from the Component paletteand drop it on the toolbar. The toolbar will take care of aligning the component.Add spacers as necessary to separate components visually. When the component is onthe toolbar, you deal with it just as you would a component on a form. I could tryto complicate this for you, but the truth is, it's just that simple. If you've nevertried to implement a combo box on a toolbar using the Windows API, you cannot appreciatehow much work Delphi saves you. Take my word for it--it's significant.</P><P>Toolbars come in many shapes and sizes, and Delphi makes creating and implementingtoolbars very easy. With Delphi, you no longer have the excuse, &quot;That's toohard!&quot; In fact, you might even enjoy creating toolbars with Delphi.</P><P><H3><A NAME="Heading5"></A>Dockable Toolbars</H3><P>Dockable toolbars are common in many Windows programs. Dockable toolbars are aparadox of sorts. On the one hand, they are a cool feature and most power users expecta good application to have dockable toolbars. On the other hand, I doubt anyone actually<I>uses</I> the docking capability of most dockable toolbars. Still, dockable toolbarsare easy enough to implement in Delphi, so you might as well provide them.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> The docking features discussed in this section apply to any windowed	control, not just to toolbars. <HR></BLOCKQUOTE><H4>Creating a Dockable Toolbar</H4><P>Making a toolbar dockable requires two steps:</P><UL>	<LI>Set the DragKind property to dkDock.	<P>	<LI>Set the DragMode property to dmAutomatic.</UL><P>After you set these two properties, you can drag your toolbar around the screen.Dragging the toolbar around the screen doesn't get you very much, though. In orderfor dockable toolbars to make sense, you have to have a target for the drop partof the drag-and-drop equation.</P><P><H4>Dock Sites</H4><P>A dockable toolbar needs to have a place to dock. As Roger Waters said, &quot;Anyfool knows a dog needs a home.&quot; Home for a dockable toolbar is a <I>dock site</I>.A dock site is any windowed component that has its DockSite property set to True.Components that are typically used as dock sites are TCoolBar, TControlBar, TPageScroller,TPanel, and TPageControl. There are other controls that have a DockSite property,but those controls are less likely to be used as dock sites.</P><P>An exercise helps illustrate the use of dock sites. Follow these steps:</P><DL>	<DT></DT>	<DD><B>1. </B>Drop a CoolBar component on a blank form. Set its DockSite property	to True.	<P>	<DT></DT>	<DD><B>2. </B>Drop a ToolBar on the CoolBar. Set the toolbar's DragKind property	to dkDock and its DragMode property to dmAutomatic. Create a few buttons on the toolbar	so that you can better see the toolbar.	<P>	<DT></DT>	<DD><B>3. </B>Place a second CoolBar on the form. Change its Align property to alBottom	and its DockSite property to True.	<P>	<DT></DT>	<DD><B>4. </B>Place a third CoolBar on the form. Change its Align property to alLeft	and its DockSite property to True. Size the CoolBar so that its width is 40 pixels	or so.	<P></DL><P>Now run the program. Drag the toolbar from dock site to dock site. Notice howthe toolbar changes its orientation when you drag it to the cool bar on the leftside of the form.</P><P>Let's experiment some more. Set each of the CoolBar components' AutoSize propertiesto True. This will cause each CoolBar to change its size based on the controls itcontains. Now run the program again and move the toolbar to the individual dock sites.Notice that each cool bar is nearly invisible until the toolbar is docked to thesite. Then the cool bar expands to contain the toolbar.</P><P><H4>Floating Toolbars</H4><P>A toolbar can be made into a floating toolbox by simply dragging the toolbar offits dock site and dropping it anywhere (anywhere other than another dock site, thatis). The toolbar becomes a floating window. You can specify the type of window thatshould host the floating dock site by setting the FloatingDockSiteClass propertyto the name of the class you want to act as the parent to the floating toolbar. Forexample, suppose that you design a form that has all the characteristics you wantfor a custom floating toolbox, and that the form is called MyToolBox. In that case,you could cause this form to be the host for a floating toolbar with this code:</P><P><PRE>ToolBar.FloatingDockSiteClass := TMyToolBox;</PRE><P>When the toolbar is undocked and the mouse button released, Delphi will automaticallycreate an instance of the TMyToolBox class and place the toolbar in the form forthat class. To dock the floating toolbox again, simply drop it on any dock site.To make a dock site accept a floating toolbox, you must respond to the OnDockOverand OnDockDrop events for the dock site. In the OnDockDrop event handler, call theManualDock method of the toolbar to cause the toolbar to dock.</P><P><H3><A NAME="Heading6"></A>Status Bars</H3><P>A status bar is another feature that makes an application more marketable. Notall applications benefit from a status bar, but many can. The VCL StatusBar component,which encapsulates the Win32 status bar control, makes creating status bars a breeze.First, take a quick look at the major properties of the StatusBar component, listedin Table 13.2.</P><P><H4>TABLE 13.2. StatusBar PROPERTIES.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Property</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">AutoHint</TD>		<TD ALIGN="LEFT">Automatically displays hints in the status bar when the mouse cursor passes over			any component whose Hint property has been set.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Panels</TD>		<TD ALIGN="LEFT">For status bars with multiple panels. This property defines the individual panels.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">SimplePanel</TD>		<TD ALIGN="LEFT">Determines whether the status bar shows a simple panel or multiple panels.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">SimpleText</TD>		<TD ALIGN="LEFT">The text for the status bar's simple panel.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Property</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">SizeGrip</TD>		<TD ALIGN="LEFT">Determines whether the status bar displays the sizing grip in the lower-right corner.			The sizing grip provides an area that the user can drag to size the window. The absence			of the sizing grip doesn't prevent the window from being sized, but the presence			of the size grip makes sizing a window easier.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">UseSystemFont</TD>		<TD ALIGN="LEFT">Always uses the current system font, overriding the settings of the Font property.			This is particularly useful for users who use Plus pack themes.</TD>	</TR></TABLE></P><P>As you can see from this table, a status bar can be a simple status bar or havemultiple panels. Let's discuss this choice next.</P><P><H4>Simple or Complex?</H4><P>A status bar can be either a simple status bar or a complex status bar. A <I>simplestatus bar</I> has a single panel that occupies the entire status bar. If you wanta simple status bar, set the SimplePanel property to True. The SimplePanel propertyacts as a toggle. You can switch between a simple and a complex status bar at runtimeby setting SimplePanel to True or False, accordingly.</P><P>A <I>complex status bar</I> is one with multiple panels. If you elect to use acomplex status bar, you can use the StatusBar Panels Editor to set up the panelsyou want to see on your status bar. To invoke the StatusBar Panels Editor, double-clickon the Value column of the Panels property. To add a panel, click the Add New buttonon the StatusBar Panels Editor. To delete a panel, click the Delete Selected button.To edit a panel, select the panel and then make changes to the panel's propertiesin the Object Inspector. Figure 13.5 shows the StatusBar Panels Editor and ObjectInspector when editing panels.</P><P><A HREF="javascript:popUp('28671305.gif')"><B>FIGURE 13.5.</B></A><B> </B><I>TheStatusBar Panels Editor.</I></P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> The individual panels in a complex status bar are instances of the	TStatusPanel class. <HR></BLOCKQUOTE><P>Most of the properties are self-explanatory, but a couple require further note.The Text property contains the text that will be displayed in the panel. You canalso use the Text property at runtime to change the text in the panel. Setting thestatus bar text is discussed a little later; you don't need to supply text for thepanel at design time if you are going to change the text at runtime.</P><P>You can set the Style property to either psText or psOwnerDraw. If the Style isset to psText (the default), the panel behaves as you would expect. The text is alignedin the panel according to the value of the Alignment property. If the Style is setto psOwnerDraw, it is up to you to draw any text or image that is displayed in thepanel. Owner drawing of panel items is discussed later in the section &quot;Owner-DrawnStatus Bar Panels.&quot;</P><P>The Width, Bevel, and Alignment properties for the panel are straightforward.Experiment with these properties to see how they affect your status bar's appearance.</P><BLOCKQUOTE>	<P><HR><strong>NOTE:</strong> In the Form Designer you immediately see the results of changes made	to the status bar via the StatusBar Panels Editor. Position the StatusBar Panels	Editor so that you can view the status bar as you work with the StatusBar Panels	Editor. Each time you make a change, it will be reflected in the Form Designer. <HR></BLOCKQUOTE><P>When you are done adding panels to the status bar, close the StatusBar Panels

⌨️ 快捷键说明

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