0

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

  • 1
    `it flickers like crazy` Yeah, well, CreateGraphics will do that to you. Call Me.Invalidate in the MouseDown event and do all of your painting in the OnPaint override. Remove DrawSomeLines. – LarsTech Apr 13 '16 at 15:53
  • Thank you for the help. I will try that and let you know of the results – WhatIsThisThing92 Apr 13 '16 at 16:13
  • Just one issue. With the DrawSomeLines(), it has a parameter in it "ByRef Which as Boolean" Basically, True make it draw one line and false makes it draw another line. Inside mousedown, the various if statements determine which to use (true or false) – WhatIsThisThing92 Apr 13 '16 at 16:36
  • I don't see enough of your code to know what that means. – LarsTech Apr 13 '16 at 16:37
  • Like, this for example. This is in mousedown events. There's multiples like this as it can draw different lines If (X + SSDiff) <= CNOP Then Call DrawSomeLines(True) If SetSST Then CalcStart(Actives) = X Else CalcStart(Actives) = X End If Call DrawSomeLines(True) Call DrawSomeLines(False) End if – WhatIsThisThing92 Apr 13 '16 at 16:40
  • True makes it draw a starting line, and false makes it draw an ending line. And the various if statements rely on data from mousedown event – WhatIsThisThing92 Apr 13 '16 at 16:41
  • So MouseDown to start a line, MouseDown again to end it? Just use a boolean variable on the first MouseDown – LarsTech Apr 13 '16 at 16:43
  • Not quite. True draws a beginning line and False draws an ending line. You always will draw both lines. You're basically setting markers for calculating within an area between the lines. So, if you change the start line with True, it will just redraw ending line with False as well on the same mousedown event and vice versa – WhatIsThisThing92 Apr 13 '16 at 16:45
  • Yeah, that's all confusing without seeing the code. Either way, it's not really the problem at hand. You just need to determine your drawing state on the MouseDown. Make sure your form has DoubleBuffered = True. – LarsTech Apr 13 '16 at 16:47
  • I went with a similar route based off of what you suggested. I called forth a second paramater into DrawSomelines, so now it is DrawSomeLines(Byval e as PaintEventArgs, ByRef Line as Boolean) and now it only flickers once very quickly and is within the realm of acceptable for myself. Thank you very much as your ideas helped me get an idea. :D – WhatIsThisThing92 Apr 13 '16 at 17:08

0 Answers0