So, in my program, I have a mousedown event that is looking for the X,Y coord of where the user clicked. Within the mousedown event is a series of 'if' conditions that determine how to call a subroutine that draws a vertical line at the X-coord of the place the user triggered the mousedown event at.
At the end of the mousedown event in VB6, was a "Refresh()". Works fine in the VB6, except in VB.net it caused timing to be off and the lines would get erased when paint event was called. To solve this, I use an "OnPaint(mypaintArgs)" inside the sub that draws the lines instead of having something for firing a paint event in the VB6 version and this works. Timing is good and lines do not get erased. Great.
Issue is, it flickers like crazy. When using a breakpoint, the paint event is fired at least five times resulting in some crazy flicker. Doublebuffer does not help, nor do any setStyles.
While I can not post the entire code for these subroutines, I CAN post enough so you guys get an idea on what is going on. Hopefully there is something that can be done to stop this insane flickering/flashing.
Here is the drawline subroutine that is called from the mousedown event for the form where the lines are drawn on:
Public Sub DrawSomeLines()
'ResizeRedraw = True
'DoubleBuffered = True
Dim gr As Graphics = Me.CreateGraphics
Dim myPaintArgs As New PaintEventArgs(gr, New Rectangle(New Point(0, 0), My.Application.OpenForms("frmDoc").Size))
'Bunch of code in here that is drawline lines
'example on line below
'mypaintargs.graphics.drawline(Pen, X1, Y1, X2, Y2)
For X = 1 To Number
Pens(X).Dispose()
Next
Me.frmDoc_Paint(Me, myPaintArgs) 'This is new. Replaced the "Refresh()" found in the mousedown event in VB6
End Sub
And here is some code from the mousedown event I can spare:
Private Sub frmDoc_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
'//Code in here for getting X and Y coord of where mouse went "down"
'code code code
'//
'//code in here calls DrawSomeLines in various ways depending on what line you need drawn
'code code code
'//
'--Refresh() 'removed due to timing being bad
End Sub
So, while it works, you get about 3 to 4 very very obvious flash/flickers. Not exactly acceptable. Was hoping someone here could lend an idea or two? Many thanks in advance