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

📄 ch07.htm

📁 delphi自学的好教材!特别适合刚刚起步学习delphi的人员!同样对使用者具有参考价值!
💻 HTM
📖 第 1 页 / 共 5 页
字号:
		<TD ALIGN="LEFT">BoundsRect</TD>		<TD ALIGN="LEFT">The rectangle of the entire component (not limited to only the client area).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Caption</TD>		<TD ALIGN="LEFT">Sets the component's caption. Many components don't have captions, so for those components			the Caption property is not exposed.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">ClientHeight</TD>		<TD ALIGN="LEFT">Contains the height of the client area of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">ClientRect</TD>		<TD ALIGN="LEFT">Contains the rectangle for the client area of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">ClientWidth</TD>		<TD ALIGN="LEFT">Contains the width of the client area of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Constraints</TD>		<TD ALIGN="LEFT">Sets the size constraints for the component (maximum width and height, minimum width			and height). More important for forms than for other components.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Ctl3D</TD>		<TD ALIGN="LEFT">Indicates whether the control should be drawn with a 3D border. If BorderStyle is			set to bsNone, this property has no effect.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Height</TD>		<TD ALIGN="LEFT">Sets the component's height.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">HelpContext</TD>		<TD ALIGN="LEFT">The HelpContext property is used to associate an index number in a help file with			a particular component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Left</TD>		<TD ALIGN="LEFT">Sets the x-coordinate of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Parent</TD>		<TD ALIGN="LEFT">A pointer to the parent of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">PopupMenu</TD>		<TD ALIGN="LEFT">Specifies the pop-up menu that will be displayed when the user clicks the secondary			mouse button.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TabOrder</TD>		<TD ALIGN="LEFT">For windowed components. Sets this component's position in the tab order.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">TabStop</TD>		<TD ALIGN="LEFT">For windowed components. Indicates that this component can be tabbed into. Setting			this property to False removes the component from the tab order.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Top</TD>		<TD ALIGN="LEFT">Sets the y-coordinate of the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Visible</TD>		<TD ALIGN="LEFT">When read, indicates whether the component is currently visible. When written to,			Visible either hides or shows the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Width</TD>		<TD ALIGN="LEFT">Sets the width of the component.</TD>	</TR></TABLE><H2><A NAME="Heading15"></A>Primary Methods of Components</H2><P>There are more than 20 methods that most components have in common. Windowed componentshave more than 40 common methods from which to choose. Interestingly, not many ofthese are widely used. Much of the functionality of components is accomplished viaproperties. For example, to hide a component, you can call the Hide method or youcan set the Visible property to False. In addition, components typically have methodsspecific to their purpose, and it will likely be those methods that you use mostwhen dealing with a particular component.</P><P>There are a few methods worthy of note, however, so I'll list them here (see Table7.2). Note that some of these methods are not available to all controls. These arenot the most often used methods common to every component, but rather the most commonlyused methods of components in general. Also, this list concentrates on componentsrepresenting controls (components placed on forms) rather than components as forms.Methods particular to forms were discussed on Day 4, &quot;The Delphi IDE Explored.&quot;</P><PRE></PRE><H4>TABLE 7.2. COMMON METHODS OF COMPONENTS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Method</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Broadcast</TD>		<TD ALIGN="LEFT">Used to send a message to all windowed child components.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">ClientToScreen</TD>		<TD ALIGN="LEFT">Converts client window coordinates into screen coordinates.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">ContainsControl</TD>		<TD ALIGN="LEFT">Returns True if the specified component is a child of the component or form.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">HandleAllocated</TD>		<TD ALIGN="LEFT">Returns True if the Handle property for the component has been created. Simply reading			the Handle property automatically creates a handle if it hasn't already been created,			so HandleAllocated can be used to check for the existence of the handle without creating			it.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Hide</TD>		<TD ALIGN="LEFT">Hides the component. The component is still available to be shown again later.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Invalidate</TD>		<TD ALIGN="LEFT">Requests that the component be redrawn. The component will be redrawn at Windows's			earliest convenience.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Perform</TD>		<TD ALIGN="LEFT">Sends a message directly to a component rather than going through the Windows messaging			system.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Refresh</TD>		<TD ALIGN="LEFT">Requests that a component be redrawn immediately and erases the component prior to			repainting.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Repaint</TD>		<TD ALIGN="LEFT">Requests that a component be redrawn immediately. The component's background is not			erased prior to repainting.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">SetBounds</TD>		<TD ALIGN="LEFT">Enables you to set the Top, Left, Width, and Height properties all at one time. This			saves time having to set them individually.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">SetFocus</TD>		<TD ALIGN="LEFT">Sets the focus to a component and makes it the active component. Applies only to			windowed components.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">Update</TD>		<TD ALIGN="LEFT">Forces an immediate repaint of the control. Typically, you should use Refresh or			Repaint to repaint components.</TD>	</TR></TABLE></P><P>Now let's take look at some of the events to which a component is most likelyto respond.</P><P><H2><A NAME="Heading16"></A>Common Events</H2><P>As with properties and methods, there are some events that will be responded tomost often. Components cover a wide variety of possible Windows controls, so eachcomponent will have individual needs. Events specific to forms are not covered herebecause I covered that information on Day 4. The most commonly used events are listedin Table 7.3.</P><P><H4>TABLE 7.3. COMMONLY HANDLED COMPONENT EVENTS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Event</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnChange</TD>		<TD ALIGN="LEFT">This event is triggered when a control changes in one way or another. Exact implementation			depends on the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnClick</TD>		<TD ALIGN="LEFT">Sent when the component is clicked with either mouse button.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnDblClick</TD>		<TD ALIGN="LEFT">This event occurs when the user double-clicks the component.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnEnter</TD>		<TD ALIGN="LEFT">This event occurs when a windowed component receives focus (is activated).</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnExit</TD>		<TD ALIGN="LEFT">This event occurs when a windowed component loses focus as the result of the user			switching to a different control. It does not occur, however, when the user switches			forms or switches to another application.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnKeyDown</TD>		<TD ALIGN="LEFT">This event is triggered when the user presses a key while the control has focus.			Keys include all alphanumeric keys as well as keys such as the arrow keys, Home,			End, Ctrl, and so on.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnKeyPress</TD>		<TD ALIGN="LEFT">This event is also triggered when the user presses a key, but only when alphanumeric			keys or the Tab, backspace, Enter, or Esc keys are pressed.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnKeyUp</TD>		<TD ALIGN="LEFT">This event occurs whenever a key is released.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnMouseDown</TD>		<TD ALIGN="LEFT">This event is triggered when the mouse button is pressed while it's over the component.			The parameters passed to the event handler give you information on which mouse button			was clicked, special keys that were pressed (Alt, Shift, Ctrl), and the x,y coordinate			of the mouse pointer when the event occurred.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnMouseMove</TD>		<TD ALIGN="LEFT">This event occurs any time the mouse is moved over the control.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnMouseUp</TD>		<TD ALIGN="LEFT">This event is triggered when the mouse button is released while over a control. The			mouse button must first have been clicked while on the control.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">OnPaint</TD>		<TD ALIGN="LEFT">This event is sent any time a component needs repainting. You can respond to this			event to do any custom painting a component requires.</TD>	</TR></TABLE><BLOCKQUOTE>	<P><HR><B>DEALING WITH MOUSE EVENTS</B></P>	<P>Mouse events have a couple of peculiarities that you should be aware of. If you	are responding just to a mouse click on a component, you will want to keep it simple	and only respond to the OnClick event. If you must use OnMouseDown and OnMouseUp,	you should be aware that the OnClick event will be sent as well as the OnMouseDown	and OnMouseUp events. For example, a single click will result in these events occurring	(and in this order):</P>	<PRE>OnMouseDownOnClickOnMouseUp</PRE></BLOCKQUOTE><PRE></PRE><BLOCKQUOTE>	<P>Similarly, when the user double-clicks with the mouse, it can result in the application	getting more events than you might think. When a component is double-clicked, the	following events occur:</P>	<PRE>OnMouseDownOnClickOnDblClickOnMouseUp</PRE></BLOCKQUOTE><PRE></PRE><BLOCKQUOTE>	<P>The point I am trying to make is that you need to take care when responding to	both double-click and single-click events for a component. Be aware that you will	get four events for a double-click event.</P>	<P>Multiple events will occur when a key is pressed, too. A keypress in an edit control,	for example, will result in OnKeyDown, OnKeyPress, OnChange, and OnKeyUp events occurring.</P>	<P>The book's code (go to <A target="_new" HREF="http://www.mcp.com/info">http://www.mcp.com/info</A>	and type 0-672-31286-7) contains a program called EventTst, which illustrates the	fact that multiple events occur on mouse clicks and keypresses. Run this program	and you will see how multiple events can be triggered based on certain user actions.	<HR></BLOCKQUOTE><P>In just a moment you're going to look at some of the VCL components in more detail.First, however, I want to introduce you to a class that is used by certain VCL components--TStrings.</P>

⌨️ 快捷键说明

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