📄 vel23.htm
字号:
<P>In addition to the property values that you can set at program design time (those listed in Table 23.2), there are additional property values that your program can add and modify at runtime. Table 23.3 lists the runtime properties available to your code.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 23.3. The grid control's runtime properties.</B></FONT></CENTER><BR><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Property</I></FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Col</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains the column number, counting from 0, of the currently selected cell.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>ColAlignment </FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains 0 (the default) for left justification of the cell values, 1 for right justification, and 2 for center alignment of the cell values. This property applies only to the cells in nonfixed columns.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>ColWidth</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the width, in twips, of an individual column.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>FixedAlignment</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains 0 (the default) for leftjustification of the cell values, 1 for right justification, and 2 for center alignment of the cell values. This property applies only to the cells in fixed columns.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>HighLight</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds True or False to indicate whether or not the user selected a cell or a range of cells.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Picture</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>At runtime, you can assign the LoadPicture() procedure (see the previous unit) to display a graphic image in a selected cell.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Row</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains the row number, counting from 0, of the currently selected cell.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>RowHeight</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the height, in twips, of an individual row.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SelEndCol</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the rightmost column of a selected range.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SelEndRow</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the bottom row of a selected range.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SelStartCol</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the leftmost column of a selected range.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SelEndCol</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the top row of a selected range.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Text</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the value of any given cell.</FONT></TABLE><P>The two most frequently used runtime property values are the Row and Col properties. These two properties determine which cell you're currently formatting and which cell you want to assign text to. Before assigning a grid's cell a value, you must set the Row and Col values to the row and column that intersect the cell to assign to.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>Many of the property values in Table 23.3 make sense only when the user runs the program because, until then, no cells are selected. The project application at the end of this lesson demonstrates how to use these properties to initialize a grid and respond to the user's selected range of cells.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The grid control is useful for displaying tables of data values for the user. The grid control is a custom control located inside the GRID.VBX file that you must add to any application that uses the grid control.<BR><BR><A NAME="E68E176"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Monitoring the Mouse Cursor</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Your program can respond to mouse movements and the user's mouse clicks through event procedures. The mouse object supports property values and methods that you can use to monitor the mouse. One important property that you may want to control during the user's mouse movement is the MousePointer property, which determines how the mouse looks when the user moves the mouse over a control.<BR><P>If you need to, you can monitor the user's mouse movements and clicks. As you've seen throughout this book, Visual Basic takes care of monitoring most of the important mouse functions. For example, you already know that if the user clicks a mouse over a command button, Visual Basic ensures that the command button's Click event procedure automatically executes without your having to worry about looking for the mouse click.<BR><P>One of the most common ways that a program works with the mouse is to change the appearance of the mouse cursor. In Windows, the term <I>cursor</I> is technically used solely for the mouse cursor, whereas the term <I>caret</I> is used for the text cursor. Despite Microsoft's original design and the technical manuals that promote these "accurate" names, most users and programmers refer to the mouse cursor simply as the <I>mouse cursor</I> and the text cursor as the <I>text cursor</I>. This chapter will continue to use the vernacular.<BR><P>Table 23.4 contains a list of every mouse cursor shape that you can display. Most controls contain the MousePointer property. For example, command buttons contain a MousePointer property. The value of each control's MousePointer property, described in Table 23.4, determines what shape the mouse cursor takes on when the user moves the mouse over that control.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 23.4. The thirteen mouse cursor values.</B></FONT></CENTER><BR><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Value</I></FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>0-Default</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The cursor assumes the control's default mouse cursor shape. Each control has its own default mouse cursor shape. Most controls use the common mouse cursor arrow for the default shape.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>1-Arrow</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The typical arrow mouse pointer. (Generally, this is the same shape as most controls' default mouse cursor shape.)</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>2-Cross</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A crosshair pointer.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>3-I-Beam</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The vertical mouse cursor most often used as a text cursor.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>4-Icon</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A small black square within another square.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>5-Size</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The sizing cursor that looks like a plus sign with arrows pointing in the four directions.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>6-Size NE SW</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A diagonal arrow pointing northeast and southwest.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>7-Size N S</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A vertical arrow pointing north and south.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>8-NW SE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A diagonal arrow pointing northwest and southeast.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>9-W E</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A vertical arrow pointing west and east.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>10-Up Arrow</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>An arrow pointing straight up.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>11-Hourglass</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The hourglass shape.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>12-No Drop</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The familiar roadsign "No" circle with a slash through it.</FONT></TABLE><P>Depending on the application, you may need to keep the user from clicking on a control. For example, you may want to ignore all clicks of a command button that prints a report of daily activities until after a 5:00 p.m. closing time. Your application could respond to the command button's click after 5:00 p.m. and return without responding if the time is before 5:00 p.m.<BR><P>During the time that the command button is to be ignored, you could set the command button's MousePointer shape to the 12-No Drop mouse cursor. Therefore, the user's mouse cursor changes to the no drop shape whenever the user moves the mouse cursor over that particular command button. The mouse cursor could remain the standard arrow pointer for the other controls. After 5:00 p.m., inside the click procedure, you could respond to the command button click by printing the report and also set the MousePointer property to 1-Default (or 1-Arrow, which is the same shape for command buttons because the default mouse cursor is the arrow for command button controls).<BR><P>Table 23.5 lists the CONSTANT.TXT file's named constants that you can use to set the MousePointer property values.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 23.5. The CONSTANT.TXT's named </B><B>MousePointer</B><B> property values.</B></FONT></CENTER><BR><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 ><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Property</I></FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><I>Description</I></FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>DEFAULT</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The control's default mouse cursor shape.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>ARROW</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The typical mouse cursor arrow.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>CROSSHAIR</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A crosshair.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>IBEAM</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>An I-Beam (the typical text cursor)</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>ICON_POINTER</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>An icon square within a square</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SIZE_POINTER</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The sizing cursor that looks like a plus sign with arrows pointing in the four directions.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SIZE_NE_SW</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A diagonal arrow pointing northeast and southwest.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SIZE_N_S</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A vertical arrow pointing north and south.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SIZE_NW_SE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A diagonal arrow pointing northwest and southeast.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SIZE_W_E</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A vertical arrow pointing west and east.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>UP_ARROW</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The straight up arrow.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>HOURGLASS</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The hourglass waiting shape.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>NO_DROP</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The "No" circle with a line through it.</FONT></TABLE><P><FONT COLOR="#FF8000"><B><I>Stop and Type: </I></B></FONT>Listing 23.2 contains the code found in this book's MOUSECH.MAK application. The program demonstrates how the mouse cursor can change depending on the value of an option button. The program produces the before 5:00 p.m. and after 5:00 p.m. results described earlier in this section.<BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Most controls support the MousePointer property that determines the shape that the mouse takes on when the user moves the mouse over another control.<BR><P><FONT COLOR="#000080"><B>Listing 23.2. Code that changes the shape of the mouse depending on the value of option buttons.</B></FONT><BR><PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -