Results 1 to 16 of 16

Thread: [RESOLVED] Prevent control flickering

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Resolved [RESOLVED] Prevent control flickering

    Hi,

    I have a very large userform with many textboxes and also panels. I have notice when I scroll up and down fast the form/controls flicker.

    I set form property
    Code:
    DoubleBuffered = True
    but it is not making much of a difference, actually I can not see a difference.

    How can I prevent this flickering please?

    Thanks

  2. #2
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    3,048

    Re: Prevent control flickering

    Hi,

    you have to set the DoubleBuffer to the Control

    put this is a Modul named modMain
    Code:
    Imports System.Reflection
    
     Public Sub DoubleBufferedPanel(ByVal myPanel As Panel, ByVal setting As Boolean)
            Dim panType As Type = myPanel.[GetType]()
            Dim pi As PropertyInfo = panType.GetProperty("DoubleBuffered", BindingFlags.Instance Or BindingFlags.NonPublic)
            pi.SetValue(myPanel, setting, Nothing)
        End Sub
    and in the Form Load
    Code:
     
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
         
            modMain.DoubleBufferedPanel(Panel1, True)
    
        End Sub
    see if it helps
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Prevent control flickering

    ChrisE: I personally prefer to inherit the control that I want double buffered then use the SetStyle method...
    That said ... in normal circumstances double buffering should only affect the owner drawing of the control itself - controls placed on another should not flicker when the parent control is scrolled...

    Have you done anything else that may be considered "special"?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Prevent control flickering

    Hi

    Have you done anything else that may be considered "special"?
    I have 114 panels and 270 textboxes on the form?

  5. #5
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Prevent control flickering

    Quote Originally Posted by schoemr View Post
    Hi



    I have 114 panels and 270 textboxes on the form?
    I suppose you know that is crazy!

    Why not use this or that instead? ie DataGridView etc.

    Does the user actually have to use that form with 270 text boxes and enter data into it that way?

    Is there a reason the panels are required? You can draw a rectangle on the form around the textboxes if that is what the panels do?

    But yes panels are blinky things. Add the double buffer. I normally use class that inherits too. However I must try ChrisE's way!

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Prevent control flickering

    Hi Tommy,

    Yes it is a very busy form. The user have to complete a lot of information. At first I decided to abandon this idea because it was too much data to process. I ended up with a database with (I can not remember the exact figure) but I was like 400 + tables. Then KPMG show me about array's and join and split, so that reduce the columns A LOT.. After that I decide to try again....

    But now the user still have to see all the fields (textboxes, labels, etc) It is required to have a view on complete form i.e. say a calculation was done and that result was captured in Section 1 of the form, then in Section 15 of the form the user must scroll up to see that value. So it is a lot of up and down scroll. It is an absolute MUST that there be only one form that user must complete.

    To divide all data in multiple forms I was told NO..

    The reason for all the panels is because some fields are grouped together (just visually) It was required that the sections have a border with a thick border width - compliments of my good friend JMC who help me with a custom panel class.


    So I have e.g. Section 1 - it is a Panel with border width = 2

    Inside the panel1 I have:

    - a title (label) on top
    - 40 Labels and 40 textboxes


    And so on.....
    Last edited by schoemr; Apr 17th, 2019 at 08:41 AM.

  7. #7
    Hyperactive Member
    Join Date
    Jun 2018
    Posts
    434

    Re: Prevent control flickering

    Quote Originally Posted by schoemr View Post
    Hi Tommy,

    Yes it is a very busy form.
    Inside the panel1 I have:

    - a title (textbox) on top
    - 40 Labels and 40 textboxes


    And so on.....
    I see.

    Well, if the panels serve no other purpose but as a border then I think you can eliminate the panels and draw the borders on the form that will stop the blinking.

    Are the panels are not for tabbing or something?

    I would try to do away with them.

    What is the data? I mean one can enter forty values into a single text box and it is easier than forty text boxes. ie you have a line feed each value is on a new line in a text box and that is one string.

    Oh...the panels help to save and restore chunks of data?

    Well, not to worry. I am sure jmc showed it for a reason.

    If everything else is working then carry on I guess and see if doublebuffered panels stop the blinking.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Prevent control flickering

    Well, not to worry. I am sure jmc showed it for a reason.
    If he not chocking in his coffee to see he is my friend

  9. #9
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Prevent control flickering

    Can you post the designer code on here and I'll see what I can do?

    Kris

  10. #10
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,040

    Re: Prevent control flickering

    I agree with getting rid of panels. Each control has a certain amount of overhead. For example, Paint events will tend to cascade as parents invalidate their children, and so on. Once you get past a certain number of controls, all the drawing can get kind of...costly. Flickering comes from either the drawing taking so long that you get to see the control erased, before you see it drawn (normally, those two follow so quickly that the erased image never actually makes it to the screen), or because there is so much going on that the screen can't completely draw in the time it has, so you get part of one image and part of the next. With a whole bunch of controls, you could have either. Getting rid of the panels would reduce the count of the number of controls, and that will help. Theoretically, you could probably get rid of the labels, too, though that may be too much work to bother with. That would require you to write the text on the form itself, which would be tedious, but getting rid of the panels would help.

    If you have to show the user all that stuff, do you have to show it all at once? One alternative would be a tab control. I believe you don't get ANY drawing for controls not on the visible tab. They may not even be created until they are needed, so that would be more efficient. More exotic types of things, like slide-in controls, or swapable panels might also work, if you are allowed to do something like that. It would avoid the scrolling, but not all the controls would really be on the form at once.
    My usual boring signature: Nothing

  11. #11
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: Prevent control flickering

    One alternative would be a tab control
    Yeah that was one of the first things that came to my mind. If your already breaking data into sections then it seem like a good fit.

  12. #12
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,764

    Re: Prevent control flickering

    Quote Originally Posted by wes4dbt View Post
    Yeah that was one of the first things that came to my mind. If your already breaking data into sections then it seem like a good fit.
    You could even make it switch to the next tab when you tabbed out of the last textbox.

    One form, 270 Textboxes!!!
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,040

    Re: Prevent control flickering

    That's not so bad. Had it been 288, then it would have been just two gross, but 270 isn't too gross.
    My usual boring signature: Nothing

  14. #14
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,388

    Re: Prevent control flickering

    VB6 used to limit you to 255

    ... Also if you really need to do it this way you could load and unload controls as the master scrollablecontrol is scrolled... so it appears the same but only has ones in the view area (or near to) loaded.

  15. #15

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2016
    Posts
    1,415

    Re: Prevent control flickering

    Hi everyone

    Yes this form was very odd from beginning... I was not sure if I even want to try this..

    Thank you for everyone advise. Here is Easter weekend so I won't have internet until next week..

    i00.............................................. I don't have that with me here it on the pc at home.. then you also never reply

    If I understand what was said here then I should remove that panel and better draw the boxes myself on the form. The only reason for wanting to use panels is because some information must be displayed in boxes (like grouped)

    So this brings me to another question but for is not related to this question so I must start a new topic..

  16. #16
    Fanatic Member Peter Porter's Avatar
    Join Date
    Jul 2013
    Location
    Germany
    Posts
    538

    Re: [RESOLVED] Prevent control flickering

    How about having a few custom transparent richtextboxes act like more. Transparent, so you could have an image of a form as your background.

    Anyway, each line of these richtextboxes will represent a textbox.

    If there are no characters on a line, the backspace would be disable to prevent that line from being removed.

    Each line would have it's own character limit.

    Enter should be disabled to prevent new lines from being created. Also disabling all ways to indent, disable Wordwrap, and ensure that items pasted are DataFormats.Text

    Clicking on a line would draw a focus glow around it's textbox on the background image.

    Transparent Richtextbox
    Code:
    Public Class TransparentRTB
        Inherits RichTextBox
    
        Public Sub InitializeComponent()
        End Sub
    
        Protected Overrides ReadOnly Property CreateParams As CreateParams
            Get
                Dim CP As CreateParams = MyBase.CreateParams
                CP.ExStyle = CP.ExStyle Or &H20
                Return CP
            End Get
        End Property
    End Class
    Last edited by Peter Porter; Apr 18th, 2019 at 11:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width