Results 1 to 6 of 6

Thread: Picturebox.Visible property within a panel.

  1. #1

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Picturebox.Visible property within a panel.

    Hi,

    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.

    Any suggestions?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  2. #2

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picturebox.Visible property within a panel.

    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
    Attached Files Attached Files
    Last edited by conipto; Nov 1st, 2005 at 03:53 PM.
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  3. #3

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picturebox.Visible property within a panel.

    Adding this loop during the form.loading event takes care of the problem:

    VB Code:
    1. Dim Cont As Control = Me
    2.         While Not Cont Is Nothing
    3.             Cont = Me.GetNextControl(Cont, True)
    4.             If Not Cont Is Nothing Then
    5.                 Dim Temp As Boolean = Cont.Visible
    6.                 Cont.Visible = True
    7.                 Cont.Visible = Temp
    8.             End If
    9.         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.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picturebox.Visible property within a panel.

    Yes, the same thing happens in 2005 Beta 2. Is there a forum or place to send bug reports for testing?

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  5. #5

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picturebox.Visible property within a panel.

    nm, found how to report it. I guess this is as resolved as possible till (read if) I hear back from them.

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  6. #6

    Thread Starter
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    Re: Picturebox.Visible property within a panel.

    Well, MS got back to me today, with this:

    Quote Originally Posted by Microsoft
    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..

    Bill
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

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