各位大侠,我在MSFlexGrid中画线,但是点单元格或移动滚动条,线条就会消失,用什么办法可以解决?
贴上画线代码如下:Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As LongPrivate Type POINTAPI
x As Long
y As Long
End TypePrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Sub Command1_Click()
Dim Pen1 As Long, Pen2 As Long
Dim Point As POINTAPI
Dim hdc As Long
Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long
With MSFlexGrid1 x1 = .ColPos(2) / Screen.TwipsPerPixelX
x2 = .ColPos(2) / Screen.TwipsPerPixelX
hdc = GetDC(.hWnd)
pen1= CreatePen(PS_SOLID, 3, vbRed)
pen2= SelectObject(hdc, Pen1)
MoveToEx hdc, x1, 0, Point
LineTo hdc, x2, 160
SelectObject hdc, pen2
DeleteObject Pen1
If .Redraw = False Then .Redraw = True
End With
End SubPrivate Sub Form_Load()
With MSFlexGrid1
.Cols = 10
.RowHeightMin = 450
End With
End Sub
贴上画线代码如下:Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As LongPrivate Type POINTAPI
x As Long
y As Long
End TypePrivate Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End TypePrivate Sub Command1_Click()
Dim Pen1 As Long, Pen2 As Long
Dim Point As POINTAPI
Dim hdc As Long
Dim x1 As Long, x2 As Long, y1 As Long, y2 As Long
With MSFlexGrid1 x1 = .ColPos(2) / Screen.TwipsPerPixelX
x2 = .ColPos(2) / Screen.TwipsPerPixelX
hdc = GetDC(.hWnd)
pen1= CreatePen(PS_SOLID, 3, vbRed)
pen2= SelectObject(hdc, Pen1)
MoveToEx hdc, x1, 0, Point
LineTo hdc, x2, 160
SelectObject hdc, pen2
DeleteObject Pen1
If .Redraw = False Then .Redraw = True
End With
End SubPrivate Sub Form_Load()
With MSFlexGrid1
.Cols = 10
.RowHeightMin = 450
End With
End Sub
为什么不用line或picturebox?