Option Explicit Public Const HS_CROSS = 4 ' +++++ Public Const BS_SOLID = 0Public Const PS_SOLID = 0 Public Const PS_GEOMETRIC = &H10000 Public Const PS_ENDCAP_FLAT = &H200 Public Const PS_JOIN_BEVEL = &H1000Public Type POINTAPI x As Long y As Long End TypePublic Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Type PAINTSTRUCT hdc As Long fErase As Long rcPaint As RECT fRestore As Long fIncUpdate As Long rgbReserved(32) As Byte End Type Public Type LOGBRUSH lbStyle As Long lbColor As Long lbHatch As Long End TypePublic Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long Public Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Public Declare Function ExtCreatePen Lib "gdi32" (ByVal dwPenStyle As Long, ByVal dwWidth As Long, lplb As LOGBRUSH, ByVal dwStyleCount As Long, lpStyle As Long) As Long Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Sub Picture1_Paint() Dim tPs As PAINTSTRUCT, lHdc As Long, RetVal As Long, strDraw As String, tTxtRect As RECT, i As Long, tBrushInfo As LOGBRUSH, lPenStyle As Long Dim tDateRect As RECT, tBeginDateRect As RECT Dim OldPen As LongWith tBrushInfo .lbColor = Picture1.ForeColor .lbHatch = HS_CROSS .lbStyle = BS_SOLID End WithlPenStyle = ExtCreatePen(PS_GEOMETRIC Or PS_SOLID Or PS_ENDCAP_FLAT Or PS_JOIN_BEVEL, 10, tBrushInfo, 0, ByVal 0&) OldPen = SelectObject(Picture1.hdc, lPenStyle)MoveToEx Picture1.hdc, 10, 100, ByVal 0 LineTo Picture1.hdc, 900, 100SelectObject Picture1.hdc, OldPen DeleteObject lPenStyleEnd Sub
还是用画点函数写画线函数?
2。LineToEx() 'API
Sub Form_Click ()
Dim CX, CY, F, F1, F2, I ' 声明变量。
ScaleMode = 3 ' 设置 ScaleMode 为像素。
CX = ScaleWidth / 2 ' 水平中点。
CY = ScaleHeight / 2 ' 垂直中点。
DrawWidth = 8 ' 设置 DrawWidth。
For I = 50 To 0 Step -2
F = I / 50 ' 执行中间步骤。
F1 = 1 - F: F2 = 1 + F ' 计算。
Forecolor = QBColor(I Mod 15) ' 设置前景颜色。
Line (CX * F1, CY * F1)-(CX * F2, CY * F2), , BFNext I
DoEvents ' 做其它处理。
If CY > CX Then ' 设置 DrawWidth。
DrawWidth = ScaleWidth / 25
Else
DrawWidth = ScaleHeight / 25
End If
For I = 0 To 50 Step 2 ' Set up loop.
F = I / 50 ' 执行中间。
F1 = 1 - F: F2 = 1 + F ' 计算。
Line (CX * F1, CY)-(CX, CY * F1) ' 画左上角。
Line -(CX * F2, CY) ' 画右上角。
Line -(CX, CY * F2) ' 画右下角。Line -(CX * F1, CY) ' 画左下角。
Forecolor = QBColor(I Mod 15) ' 每次改变颜色。
Next I
DoEvents ' 进行其它处理。
End Sub
[email protected]
Dim k#, CurColor&
Me.DrawWidth = 50
Me.DrawMode = 13
Me.Line (400, 400)-(Me.ScaleWidth - 800, Me.ScaleHeight - 800)
k = (Me.ScaleHeight - 800) / (Me.ScaleWidth - 800)
CurColor = Me.ForeColor
Me.ForeColor = Me.BackColor
Me.Line (400 + 300 * k, 400 - 300)-(400 - 300 * k, 400 + 300)
Me.ForeColor = CurColor
回复人: sssoft(恒谦) (2001-9-8 12:53:19) 得0分
如果是写到打印机上,把me换成printer就可以了
Public Const HS_CROSS = 4 ' +++++
Public Const BS_SOLID = 0Public Const PS_SOLID = 0
Public Const PS_GEOMETRIC = &H10000
Public Const PS_ENDCAP_FLAT = &H200
Public Const PS_JOIN_BEVEL = &H1000Public Type POINTAPI
x As Long
y As Long
End TypePublic Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Type PAINTSTRUCT
hdc As Long
fErase As Long
rcPaint As RECT
fRestore As Long
fIncUpdate As Long
rgbReserved(32) As Byte
End Type
Public Type LOGBRUSH
lbStyle As Long
lbColor As Long
lbHatch As Long
End TypePublic Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As Any) As Long
Public Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Public Declare Function ExtCreatePen Lib "gdi32" (ByVal dwPenStyle As Long, ByVal dwWidth As Long, lplb As LOGBRUSH, ByVal dwStyleCount As Long, lpStyle As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As LongPrivate Sub Picture1_Paint()
Dim tPs As PAINTSTRUCT, lHdc As Long, RetVal As Long, strDraw As String, tTxtRect As RECT, i As Long, tBrushInfo As LOGBRUSH, lPenStyle As Long
Dim tDateRect As RECT, tBeginDateRect As RECT
Dim OldPen As LongWith tBrushInfo
.lbColor = Picture1.ForeColor
.lbHatch = HS_CROSS
.lbStyle = BS_SOLID
End WithlPenStyle = ExtCreatePen(PS_GEOMETRIC Or PS_SOLID Or PS_ENDCAP_FLAT Or PS_JOIN_BEVEL, 10, tBrushInfo, 0, ByVal 0&)
OldPen = SelectObject(Picture1.hdc, lPenStyle)MoveToEx Picture1.hdc, 10, 100, ByVal 0
LineTo Picture1.hdc, 900, 100SelectObject Picture1.hdc, OldPen
DeleteObject lPenStyleEnd Sub