Results 1 to 10 of 10

Thread: [RESOLVED] Inefficient redraw on multiple child control move?

  1. #1

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

    Resolved [RESOLVED] Inefficient redraw on multiple child control move?

    Ok... if I have a panel with (for example) 3 controls on them (non transparent bg) ... and I move them all within the one sub eg:

    vb Code:
    1. for each control in panel.controls.oftype(of control)
    2.     control.left+=3
    3. next

    The paint event to get called multiple times???

    Is there a way to change this behaviour?

    I cannot even seem to set a flag as the control redraws after all controls are moved

    Strange... because if I go like this:

    vb Code:
    1. for i=1 to 3
    2.     panel.invalidate
    3. next

    The paint only gets called once, I thought this would be the same when moving controls?

    Any ideas?
    Thanks,
    Kris

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Inefficient redraw on multiple child control move?

    I'm not sure whether this will work or not but try calling SuspendLayout on the Panel first and then ResumeLayout when you're done.

  3. #3

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

    Re: Inefficient redraw on multiple child control move?

    Quote Originally Posted by jmcilhinney View Post
    I'm not sure whether this will work or not but try calling SuspendLayout on the Panel first and then ResumeLayout when you're done.
    Nope ... shame

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Inefficient redraw on multiple child control move?

    Are you able to upload your project? I just tested with a brand new project with three Buttons on a Panel and your exact code and they all appeared to move in unison to me. That was VS 2013 on Windows 8.1.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,301

    Re: Inefficient redraw on multiple child control move?

    I tried it again with 14 Buttons and it still looked simultaneous. Maybe it's the type of control.

  6. #6

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

    Re: Inefficient redraw on multiple child control move?

    Quote Originally Posted by jmcilhinney View Post
    I tried it again with 14 Buttons and it still looked simultaneous. Maybe it's the type of control.
    vb Code:
    1. Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    2.     Debug.Print(Now.ToShortTimeString & " - Panel1_Paint()")
    3. End Sub
    4.  
    5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.     For Each control In Panel1.Controls.OfType(Of Control)()
    7.         control.Left += 3
    8.     Next
    9. End Sub

    See how often the debug message gets fired when you click the button... the more controls you add the slower it becomes... if you have something complex in the paint event

    Kris

  7. #7
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

    Re: Inefficient redraw on multiple child control move?

    You might want to try these two possible solutions:-
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  8. #8

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

    Re: Inefficient redraw on multiple child control move?

    Quote Originally Posted by Niya View Post
    You might want to try these two possible solutions:-
    I had actually already tried the 2nd one (and I thought LockWindowUpdate did the same thing to the window??) before posting here... same thing...

    Kris

  9. #9
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,372

    Re: Inefficient redraw on multiple child control move?

    Quote Originally Posted by i00 View Post
    vb Code:
    1. Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    2.     Debug.Print(Now.ToShortTimeString & " - Panel1_Paint()")
    3. End Sub
    4.  
    5. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    6.     For Each control In Panel1.Controls.OfType(Of Control)()
    7.         control.Left += 3
    8.     Next
    9. End Sub

    See how often the debug message gets fired when you click the button... the more controls you add the slower it becomes... if you have something complex in the paint event

    Kris
    i took your code, put it into a new project, put a panel1 onto the form, one button1 outside the panel, three new buttons inside. when i click button1 i do only get one Panel1_Paint() message. if i move the mouse over the three buttons i do receive multiple paints but that is a different story. maybe something else is causing the multiple paints for you?

    BTW why don't you move the panel instead of all controls within the panel?

  10. #10

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

    Re: Inefficient redraw on multiple child control move?

    Quote Originally Posted by digitalShaman View Post
    i took your code, put it into a new project, put a panel1 onto the form, one button1 outside the panel, three new buttons inside. when i click button1 i do only get one Panel1_Paint() message. if i move the mouse over the three buttons i do receive multiple paints but that is a different story. maybe something else is causing the multiple paints for you?

    BTW why don't you move the panel instead of all controls within the panel?
    Thanks for that ... I checked it and your right...

    The combo boxes were the culprit ... strange... since they don't really have transparent backgrounds (I don't think they can have rounded corners for eg?) ...
    Just put them on a panel and all is working

    Kris

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