读书人

求救MSFLEXGRID画线消失!解决方法

发布时间: 2012-01-19 00:22:28 作者: rapoo

求救MSFLEXGRID画线消失!
各位大侠,我在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 Long

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private 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 Sub

Private Sub Form_Load()
With MSFlexGrid1
.Cols = 10
.RowHeightMin = 450
End With
End Sub

[解决办法]
嗯,画到窗体上么,被挡住。
为什么不用line或picturebox?
[解决办法]
我懂你的意思,为什么呢。我也不知道。
可以换个方法呢。
[解决办法]
改为实时添加Line对象
[解决办法]
因为msflexgrid的redraw为true,当其上有动作时会重画"运动"部分,可以当你有动作时不停的重绘你的线条

读书人网 >VB

热点推荐