vel22.htm
来自「简单的说明如何使用VB,非常适合初学使用者,而且是用图表来解说的」· HTM 代码 · 共 1,821 行 · 第 1/3 页
HTM
1,821 行
</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A rectangle</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>1-Square</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SHAPE_SQUARE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A square</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>2-Oval</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SHAPE_OVAL</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>An oval</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>3-Circle</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SHAPE_CIRCLE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A circle</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>4-Rounded Rectangle</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SHAPE_ROUNDED_RECTANGLE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A rectangle with rounded corners</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>5-Rounded Square</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>SHAPE_ROUNDED_SQUARE</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>A square with rounded corners</FONT></TABLE><P><FONT COLOR="#FF8000"><B><I>Stop and Type: </I></B></FONT>Figure 22.6 provides a simple shape application that changes the shape as the user presses the command button. You can load and run the SHAPECH.MAK application on this book's disk if you want to study the application.<BR><P><B> <A HREF="22vel06.gif">Figure 22.6. Changing the shape with the click of a button.</A></B><BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>The shape control provides six of the seven fundamental geometric shapes that you can place on a form. The Shape property determines the outline of the shape.<BR><BR><A NAME="E68E169"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>If You Have Graphics Files...</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>Visual Basic supports two additional graphics controls that don't draw graphics but with which you can place icons and graphic bitmap images that you may have on the disk.<BR><P>Figure 22.7 shows the location of two additional graphics-related controls called the picture box control and the image control. These two controls are virtually identical and enable you to load disk images onto your application's form.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>The picture box control provides a few advanced features that you can tap into if you ever write <I>MDI</I> (<I>multiple document interface</I>) applications. The image box control is more efficient and displays images faster than the picture box.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P><B> <A HREF="22vel07.gif">Figure 22.7. The picture box and image control on the toolbox.</A></B><BR><P>Here are the three kinds of graphics files that these controls can load from the disk and display on a form:<BR><UL><LI><I>Bitmap files</I> that end with the .BMP or .DIB filename extensions<BR><BR><LI><I>Icon files</I> that end with the .ICO filename extension<BR><BR><LI><I>Metafiles</I> that end with the .WMF filename extension<BR><BR></UL><P>Where do you get these graphic files? None come with the Visual Basic Primer system (graphic images consume lots of disk space). There are several sources available. If you use the Microsoft Paintbrush program supplied with Windows, you can create bitmap files. Icon files are compact graphics files that contain the picture icons that you see in a Windows Program Manager group. Several various Windows applications store graphic images in the metafile format.<BR><P>Table 22.6 contains the vital and common properties available for both the picture box and image controls. The most important value is the Picture property that contains the complete filename and pathname to the picture displayed inside the control.<BR><BR><P ALIGN=CENTER><CENTER><FONT COLOR="#000080"><B>Table 22.6. The picture box and image controls' 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>BorderStyle</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Describes the style of the border around the image. If set to 0-None (the default), no border appears around the image. If 1-Fixed Single, a dark border line appears around the image.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Height</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains the height, in twips, of the image. (See Stretch.)</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Left</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Holds the number of twips from the left edge of the Form window to the left edge of the image.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Name</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains the name of the picture box or image. Visual Basic names the picture box controls Picture1, Picture2, and so on, and Visual Basic names the image control Image1, Image2, and so on unless you rename the controls.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Picture</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Contains a complete path and filename to the image that Visual Basic will display in the control at runtime. No image appears inside the control until the user runs the program.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Stretch</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>(For image controls only.) If set to False, (the default) the control resizes automatically to fit the size of the graphic image. No matter what size you specify for the image control, the control will resize to the exact size of the disk file's graphic image as if to <I>shrinkwrap</I> around the image. If set to True, the image resizes to fit the shape of the control.</FONT><TR><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>Width</FONT><TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>The width, in twips, of the control. (See Stretch.)</FONT></TABLE><P>When you want to put a graphic image on your form, you only need to place an image (or picture box) control on the form and specify a filename for the image that you want the control to display. Open a new form and follow these steps to create an application with an image:<BR><OL><LI>Double-click the image control to place the control in the middle of the form.<BR><BR><LI>Press F4 to display the Property window.<BR><BR><LI>Click the Picture property. You'll see an ellipsis appear where you normally enter property values.<BR><BR><LI>If you click the ellipsis, Visual Basic opens a Load Picture dialog box like the one shown in Figure 22.8. In the dialog box, you specify any file, including the path, that holds the image you want to display on your form.<BR>The Picture property continues to hold the pathname and filename of the image that you place on the form. At runtime, Visual Basic will display the image in the place of the control.<BR><BR></OL><P><B><A HREF="22vel08.gif">Figure 22.8. The Load Picture dialog box for filling in the </B><B>Picture</B><B> property.</A></B><BR><P>You also can change a graphic file that appears in an image or picture box control using Visual Basic code. The LoadPicture function loads specific graphic files into graphic controls to display those graphics on the form. The following statement changes the picture file used for an image control named imgFace:<BR><BR><PRE><FONT COLOR="#000080">imgFace.Picture = LoadPicture("D:\FIGS\FACE.BMP")</FONT></PRE><P>You can replace pictures during runtime by loading different files using the LoadPicture() function.<BR><P><B>Tip: </B>By using a null string, "", for the LoadPicture() argument, you can erase a picture from a picture box or image control.<P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>This section wraps up the discussion on combining graphics with Visual Basic programs. Not only does Visual Basic provide the tools needed to draw your own pictures, but Visual Basic also enables you to load images from disk files onto your own forms.<BR><BR><A NAME="E68E170"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>Homework</B></FONT></CENTER></H3><BR><BR><A NAME="E69E155"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>General Knowledge</B></FONT></CENTER></H4><BR><OL><LI>What two controls enable you to draw geometric shapes on a form?<BR><BR><LI>How many different shapes does the shape control produce?<BR><BR><LI>Which property value determines the pattern of drawn lines?<BR><BR><LI>Which property value determines the shape of objects drawn with the shape control?<BR><BR><LI>What two controls enable you to load graphic file images onto a form?<BR><BR><LI>Which graphic image control is the most efficient of the two controls?<BR><BR><LI>What three kinds of graphics files can Visual Basic display on a form?<BR><BR><LI>Which property forces a graphic image to shrinkwrap around the picture box or image control?<BR><BR><LI>Which control property determines the path and filename of the graphic image to display?<BR><BR><LI>What is the name of the Visual Basic function that loads graphic file images at runtime?<BR><BR></OL><BR><A NAME="E69E156"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Find the Bug</B></FONT></CENTER></H4><BR><OL><LI>Jean has drawn a thick line that measures 15 twips. Jean wants to use the line to separate a large form message from the rest of the controls on her form. The trouble that Jean can't seem to overcome is that she wants the thick line to appear as a series of dashes. Visual Basic refuses to honor her BorderStyle request and always displays a solid line. Explain to Jean what her problem is.<BR><BR><LI>Can you think of a roundabout way to accomplish Jean's thick, dashed line?<BR><BR></OL><BR><A NAME="E69E157"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>What's the Output?</B></FONT></CENTER></H4><BR><OL><LI>Gordon wrote a program that contains the following statement:<BR>imgPainting.Picture = LoadPicture("")<BR>What appears on the image control when Gordon's application calls the LoadPicture() function?<BR><BR></OL><BR><A NAME="E69E158"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Write Code That...</B></FONT></CENTER></H4><BR><OL><LI>Suppose that you want to draw a rectangle with a blue border, red diagonal lines, and a green interior. Describe the shape control's properties that you would have to set to a blue, red, and green color.<BR><BR></OL><BR><A NAME="E69E159"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Extra Credit</B></FONT></CENTER></H4><BR><P>Write a program that draws a large green happy face in the center of the form. Add a command button that the user can click to blink one of the happy face's eyes.<BR><P ALIGN=LEFT><A HREF="vel21.htm" TARGET="_self"><IMG SRC="purprev.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Previous Page"></A><A HREF="#I0" TARGET="_self"><IMG SRC="purtop.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Page Top"></A><A HREF="index.htm" TARGET="_self"><IMG SRC="purtoc.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="TOC"></A><A HREF="velp11.htm" TARGET="_self"><IMG SRC="purnext.gif" WIDTH = 32 HEIGHT = 32 BORDER = 0 ALT="Next Page"></A></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?