Let's introduce several functions of rectangle drawing:
DrawFocusRect (): Draw a focus rectangle;
Rectangle (): Draws a rectangle with the currently selected brush and fills it with the currently selected paint brush;
Drawedge (): depicts a rectangle's border with the specified style;
RoundRect (): Draws a rounded rectangle with the currently selected brush and fills it with the currently selected paint brush.
Today is the DrawFocusRect () function, the function prototype is as follows
Private Declare Function drawfocusrect Lib "user32" Alias "DrawFocusRect"
(
ByVal HDC as Long,
LpRect as RECT
) as Long
Hdc:long//Handle of the device
Lprect:rect the structure, drawing the coordinates of the rectangle.
A return value of 0, indicating failure, not 0, succeeds
Example: Drawing a rectangle
Option explicitprivate type Rectleft as longtop as longright as longbottom as Longend Type'type declarationPrivate Declare Function DrawFocusRect Lib"User32"(ByVal hdc as Long, LpRect as RECT) as Longdim Flag as Booleandim Start as Booleandim Pos as Rectdim Temppos as RECTP Rivate Sub Command1_Click () Flag=True'Start DrawingEnd subprivate Sub command2_click () Flag=Falsepicture1.cls'End DrawingEnd subprivate Sub form_load () Flag=Falsestart=False'Prohibit drawingMe.scalemode =3Me.Picture1.ScaleMode=3'set object coordinates in pixelsEnd subprivate Sub picture1_mousedown (Button As Integer, Shift As Integer, X as single, Y as single) If Flag Thenstart =Truepos.left=Xpos.top=Yelsestart=falseend IfEnd SubPrivate Sub picture1_mousemove (Button As Integer, Shift As Integer, X as single, Y as single) If Sta RT Thendrawfocusrect Me.Picture1.hdc, Pos'Erase original Focus RectanglePos.right =Xpos.bottom=ydrawfocusrect Me.Picture1.hdc, Pos'draw a new focus rectangleEnd IfEnd SubPrivate Sub picture1_mouseup (Button As Integer, Shift As Integer, X as single, Y as single) If Start thend Rawfocusrect Me.Picture1.hdc, Pos'Erase original Focus RectanglePos.right =Xpos.bottom=ydrawfocusrect Me.Picture1.hdc, Pos'draw a new focus rectangleStart =FalseEnd IfEnd Sub
VB API 11th Lesson Draw Rectangle