I have a strange problem. I have in this case 6 pictureboxes inside a scrolling panel. I have these picture boxes showing and hiding based on events happening elsewhere in the panel. However, if I scroll the panel to another position down, and set the picturebox.visible property, they appear where they would if I was scrolled all the way to the top (rather than just becoming visible where I tell them to). Only two of my 6 pictureboxes do this. I thought perhaps that they were somehow not contained in the panels control collection, but two things verified this was not the case. First, I set a button to cycle through the panel's ControlCollection and change each pictureboxes image property to a solid blue bitmap, and they changed as well. Second, when I Scroll the panel after they have "jumped" they scroll with it, in the incorrect place.
Nowhere in my form is the location property of these pictureboxes set, and it bugs me that only 2 of the 6 (which I created all at the same time) do this.
Also, it seems to happen during a period where my program is "Thinking", and setting a large number of variables. It does not happen every time, but most of the time. Only the Y position is affected.
Ok, I tried putzing around with it, and nothing I do makes a difference. I copied my project to another folder, deleted EVERYTHING but the pictureboxes and one method to show and hide all of them. It seems to happen only on the first occurence of picturebox.visible. For instance, if I start out with some of them hidden, if the visible property is changed while the picturebox is out of sight in the panel, the first time it is set to visible, then it happens. I attatched the code of my stripped down project. If on startup you scroll down and click the button that shows the pictureboxes (on the right), you can see what's happening.
Thanks,
Bill
Last edited by conipto; Nov 1st, 2005 at 03:53 PM.
Adding this loop during the form.loading event takes care of the problem:
VB Code:
Dim Cont As Control = Me
While Not Cont Is Nothing
Cont = Me.GetNextControl(Cont, True)
If Not Cont Is Nothing Then
Dim Temp As Boolean = Cont.Visible
Cont.Visible = True
Cont.Visible = Temp
End If
End While
So it seems to be that controls invisible at start up are not properly created if the form is scrolled at all when the visible property it set to true for the first time. Is there a logical explanation for this, or is it possibly a bug in the framework? I'm gonna try it with 2005 to see if it still happens.
Thank you for your bug report. The way the AutoScroll system works is that the location of the control changes when you scroll. When a control window (hWnd or sometimes called its handle) is created the location of that control is set. That location is not based upon the auto scroll system, but based upon the physical 0,0 location (logical 0,0 location would take the autoscroll into account). In your sample the handle/hWnd is not created until the Visible property is set to true, so where ever you are scrolled to will have the control placed there. What you need to do is to force the handle creation of the pictureboxes/labels as your application/control is being initialized. I would recommend placing all your pictureboxes and labels in a panel and then forcing the panel's handle to be created. You can force the handle to be created by the following line:
Dim hdl as IntPtr = panelForPictureBoxes.Handle
I would also recommend setting the new panel's Visible property to be false and the pictureboxes and labels to be Visible true. In your button click you would only set the panel's visible property to true. This is more efficient.
Hope this helps,
mark
program manager
Seems like an odd response to suggest i add another (in this case 6!) more controls to the form to fix it. I'll stick to my little form load loop for now, i've had enough of panels anyways..