Click here to Skip to main content
15,894,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
as of now I am able to do this from a separate event,

here is the code I am using:

Private Sub ListView1_DrawSubItem(sender As Object, e As System.Windows.Forms.DrawListViewSubItemEventArgs) Handles ListView1.DrawSubItem
       With e.Graphics
           .DrawLines(New Pen(SystemColors.ButtonShadow), New Point() {New Point(e.Bounds.Left, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top - 1), New Point(e.Bounds.Left + e.Bounds.Width, e.Bounds.Top + e.Bounds.Height), New Point(e.Bounds.Left, e.Bounds.Top + e.Bounds.Height)})

       End With

       e.DrawText()

   End Sub


The reason I am trying to get this over to the form_load event is that every time I call forth my listview1.click event the listview keeps flashing. However, I believe this may stop if this was drawn on listview permanently instead of being its own event being drawn every time.

What I have tried:

I tried using a creategraphics

here is the code I tried:

With CreateGraphics()
          .DrawLines(New Pen(SystemColors.ButtonShadow), New Point() {New Point(ListView1.Bounds.Left, ListView1.Bounds.Top - 1), New Point(ListView1.Bounds.Left + ListView1.Bounds.Width, ListView1.Bounds.Top - 1), New Point(ListView1.Bounds.Left + ListView1.Bounds.Width, ListView1.Bounds.Top + ListView1.Bounds.Height), New Point(ListView1.Bounds.Left, ListView1.Bounds.Top + ListView1.Bounds.Height)})
      End With


but it didn't work
Posted
Updated 27-Apr-18 5:29am
Comments
Richard Deeming 26-Apr-18 14:29pm    
You're trying to solve the wrong problem. Don't try to move the drawing code to the load event - that will never work. Instead, try to solve the flashing problem.

You probably need to turn on double buffering:
How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls[^]
Member 11856456 26-Apr-18 14:42pm    
This seems like it would solve my problem, the only issue is that it shows how to do this in C#, not vb.net. How would I go about setting this up for a vb.net application?
Richard Deeming 26-Apr-18 14:44pm    
The two code blocks are simple enough to translate:
DoubleBuffered = True
and:
SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
Member 11856456 26-Apr-18 15:02pm    
I just tried this in 3 different locations of my code and none of them responded to the flickering. maybe I am looking at this wrong?
Member 11856456 27-Apr-18 11:31am    
Richard, I could not get the double buffer to work, however, I did find a code that stops flickering. Since you have been in this for awhile, and it's a shortcode, could you explain why this stops flickering?

1 solution

After a couple days of searching and trying different things, I found the solution I was looking for. However, I do not completely understand how it works, but it does stop the flickering.

Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams 'stop flicker code part 1 of 2
      Get
          Dim cp As CreateParams = MyBase.CreateParams
          cp.ExStyle = cp.ExStyle Or 33554432
          Return cp
      End Get
  End Property
  Private Sub PreVentFlicker() 'stop flicker code part 2 of 2
      With Me
          .SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
          .SetStyle(ControlStyles.UserPaint, True)
          .SetStyle(ControlStyles.AllPaintingInWmPaint, True)
          .UpdateStyles()
      End With
  End Sub


http://www.dreamincode.net/forums/topic/294248-flicker-problem-on-form-loading/
 
Share this answer
 
Comments
Richard Deeming 27-Apr-18 11:37am    
In the CreateParams method, 33554432 is WS_CLIPCHILDREN:
Window Styles (Windows)[^]

The other code turns on the "double buffered" flag; sets the form to paint itself, instead of relying on the OS; and tells the form to ignore the WM_ERASEBKGND message to reduce flickering.
ControlStyles Enum[^]

They're all related to reducing the number of times the control has to be painted, which will reduce the flickering.
Member 11856456 27-Apr-18 11:46am    
Thank you very much. I haven't made it that far into programming. However, since I have been on this site I have learned a whole lot. Again thanks for the help in understanding the code provided.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900