继承Panel 控件写个表格控件,在滚动时,如果单击滚动条则正确,如果直接用鼠标滚动,则出现错误,
如题,好奇怪,难道直接用鼠标滚动跟点击滚动条的滚动还有区别吗?
已经设置好下面的属性
AutoScroll = True
AutoScrollMinSize
下面是实现重绘的代码
Private Sub flyTableSet_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
If T IsNot Nothing Then
Dim g As Graphics = e.Graphics
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y)
'绘制背景
g.FillRectangle(Brushes.White, New Rectangle(New Point(0, 0), T.size))
g.DrawRectangle(Pens.Red, New Rectangle(New Point(0, 0), T.size))
For Each r As Row In T.Rows
For Each c As Cell In r.cells
g.DrawRectangle(Pens.Black, c.Rect)
Next
Next
End If
End Sub
[解决办法]
mark
[解决办法]
是不是跟鼠标事件有冲突?
[解决办法]
用现成的吧。
[解决办法]
写一个绘制缓冲位图,鼠标滚动可能造成GDI失败
Paint事件中处理大面积的重画是非常不明智的。
private bm as new bitmap(x,y)
private g as Graphics =Graphics.fromimage(bm)
sub mydraw()
g.draw...........
flyTableSet.CreateGraphics.DrawImage(bm)
end sub
Private Sub flyTableSet_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
'只画出需要更新的部分
e.Graphics.DrawImage(bm, e.ClipRectangle, e.ClipRectangle, GraphicsUnit.Pixel)
End Sub
[解决办法]
我觉得,可能是用鼠标点击时点击速度还能使代码来得及响应,但如移动鼠标就要重绘或者滚动鼠标来说,变化频率过快,使得代码来不及反应吧。