-
Mar 23rd, 2015, 07:37 PM
#1
[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:
for each control in panel.controls.oftype(of control)
control.left+=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:
for i=1 to 3
panel.invalidate
next
The paint only gets called once, I thought this would be the same when moving controls?
Any ideas?
Thanks,
Kris
-
Mar 23rd, 2015, 07:45 PM
#2
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.
-
Mar 23rd, 2015, 08:47 PM
#3
Re: Inefficient redraw on multiple child control move?
Originally Posted by jmcilhinney
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
-
Mar 23rd, 2015, 10:06 PM
#4
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.
-
Mar 23rd, 2015, 10:09 PM
#5
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.
-
Mar 23rd, 2015, 11:21 PM
#6
Re: Inefficient redraw on multiple child control move?
Originally Posted by jmcilhinney
I tried it again with 14 Buttons and it still looked simultaneous. Maybe it's the type of control.
vb Code:
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint Debug.Print(Now.ToShortTimeString & " - Panel1_Paint()") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each control In Panel1.Controls.OfType(Of Control)() control.Left += 3 Next 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
-
Mar 24th, 2015, 03:17 AM
#7
Re: Inefficient redraw on multiple child control move?
You might want to try these two possible solutions:-
-
Mar 25th, 2015, 08:37 PM
#8
Re: Inefficient redraw on multiple child control move?
Originally Posted by Niya
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
-
Mar 26th, 2015, 02:37 AM
#9
Re: Inefficient redraw on multiple child control move?
Originally Posted by i00
vb Code:
Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint Debug.Print(Now.ToShortTimeString & " - Panel1_Paint()") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each control In Panel1.Controls.OfType(Of Control)() control.Left += 3 Next 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?
-
Apr 5th, 2015, 09:42 PM
#10
Re: Inefficient redraw on multiple child control move?
Originally Posted by digitalShaman
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|