重拾VB625:Using Graphics Methods

来自MSDN-2001-OCT: Visual Tools and Languages/Visual Studio 6.0 Documentation/Visual Basic Documentation/Using Visual Basic/Programmer’s Guide/Part 2: What Can You Do With Visual Basic/Working with Text and Graphics/

1. basics of Graphics Methods

(1)

Method Description
Cls Clears all graphics and Print output.
PSet Sets the color of an individual pixel.
Point Returns the color value of a specified point.
Line Draws a line,rectangle,or filled-in box.
Circle Draws a circle,ellipse,or arc.
PaintPicture Paints graphics at arbitrary locations.

(2) The graphics methods work well in situations where using graphical controls require too much work.

(3) Graphics methods offer some visual effects that are not available in the graphical controls. For example,you can only create arcs or paint individual pixels using the graphics methods.

(4) Graphics you create with these graphics methods appear on the form in a layer of their own. This layer is below all other controls on a form,so using the graphics methods can work well when you want to create graphics that appear behind everything else in your application.

(5) 短处:在设计时不可见(而用图形控件则可在设计时就知道效果)。

(6) Every graphics method draws output on a form,in a picture box,or to the Printer object. To indicate where you want to draw,precede a graphics method with the name of a form or picture box control.

Each drawing area has its own coordinate system that determines what units apply to the coordinates. In addition,every drawing area has its own complete set of graphics properties.

2. Drawing points,lines,boxes,circles,ellipses,pictures

(1) You can precede each of these points with the Step keyword,specifying that the location of the point is relative to the last point drawn.

(2) 用Line可以画box: 直接画4条线或用B参数。还可用F参数及指定填充颜色和FillStyle。

(3) The Circle method draws a variety of circular and elliptical (oval) shapes. In addition,Circle draws arcs (segments of circles) and pie-shaped wedges.

(4) The PaintPicture method can be used in place of the BitBlt Windows API function to perform a wide variety of bit operations while moving a rectangular block of graphics from one position to any other position.

The pic argument must be a Picture object,as from the Picture property of a form or control.

3. DrawWidth,DrawMode

(1) The DrawWidth property specifies the width of the line for output from the graphics methods. The BorderWidth property specifies the outline thickness of line and shape controls.

(2) The DrawMode property determines what happens when you draw one pattern on top of another.

(3) (4)

Setting Description
4 Not Copy Pen. Draws the inverse of the line pattern,regardless of what is already there.
7 Xor Pen. Displays the difference between the line pattern and the existing display,as explained later in this section. Drawing an object twice with this mode restores the background precisely as it was.
11 No operation. In effect,this turns drawing off.
13 Copy Pen (default). Applies the line’s pattern,regardless of what is already there.

4. Creating Graphics When a Form Loads

When creating graphics that appear on a form when it loads,consider placing the graphics methods in the Form_Paint event. Form_Paint graphics will get repainted automatically in every paint event. If you place graphics in the Form_Load event,set the AutoRedraw property on the form to True. In this case,Form_Load should show the form,then draw the graphics. Remember,forms are not visible during the Form_Load event. Because Visual Basic does not process graphics methods on a form that is not visible,graphics methods in the Form_Load event are ignored unless AutoRedraw is set to True.

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...