locked
Scroll panel resets to top after Message Box RRS feed

  • Question

  • I have a AutoScroll panel that I dynamically add controls to.
    The AutoScroll aspects works perfectly fine.  Scroll bars appear, I can navigate.

    However, if I open a message box on that form, the scroll panel resets back to the top.
    Also if I open a new form, with this form as a parent, the scroll panel resets back to the top (as you woudl expect as they are both dialog forms).

    I can't find an event that is firing, and I can't find anything that I set that woudl cause this (as it is happening in several places where I use the same technqiue layout)

    Any ideas?
    Thursday, August 6, 2009 6:42 PM

Answers

  • Hi,

    I have had a look at this and there seems to be a property that should solve this issue however setting the property doesn't seem to help. The code I had is as follows :-

                Point previousPosition = panel1.AutoScrollPosition;
    
                System.Windows.Forms.MessageBox.Show("Test");
    
                panel1.AutoScrollPosition = previousPosition;
    I would have thought the above would have worked, however it doesn't seem to. Even setting the AutoScrollPosition without displaying the message box doesn't scroll the Panel.

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked as answer by ZHE ZHAO Thursday, August 13, 2009 3:00 AM
    Tuesday, August 11, 2009 6:10 PM
  • Hi,

     

     

    Thank you Paul for pointing the problem out. I am sorry Fontano, I have misunderstood your problem.

    If I understand you correctly this time, the behavior you got is sometime by design.

    As a workaround, we can use System.Drawing.Point to store value of the AutoScrollPosition of the Panel as Paul recommended. However, Panel.AutoScrollPositon.X and Panel.AutoScrollPositon.Y contain negative values, we need to use Math.Abs to obtain a positive value.

    For example:

     

    panel1.AutoScrollPosition = new Point(Math.Abs(panel1.AutoScrollPosition.X), Math.Abs(CurrentPoint.Y));

     

    This link has a detail description of scroll position problem in an auto-scrollable Panel

    http://support.microsoft.com/default.aspx/kb/829417

     

    Regards,

    Zhe Zhao

    • Proposed as answer by Paul Diston Wednesday, August 12, 2009 6:00 AM
    • Marked as answer by ZHE ZHAO Thursday, August 13, 2009 1:57 AM
    Wednesday, August 12, 2009 5:55 AM

All replies

  • Hi Fontano,

     

    Have tried to set dock or anchor property of the panel to fix panel position on your windows.

    Dock Property

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx

    Anchor Property

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx

    Hope it helps.

     

    Regards,

    Zhe Zhao

     

    Tuesday, August 11, 2009 7:30 AM
  • Hi,

    I have had a look at this and there seems to be a property that should solve this issue however setting the property doesn't seem to help. The code I had is as follows :-

                Point previousPosition = panel1.AutoScrollPosition;
    
                System.Windows.Forms.MessageBox.Show("Test");
    
                panel1.AutoScrollPosition = previousPosition;
    I would have thought the above would have worked, however it doesn't seem to. Even setting the AutoScrollPosition without displaying the message box doesn't scroll the Panel.

    Thanks

    Paul Diston
    http://www.smartmobiledevice.co.uk/
    • Marked as answer by ZHE ZHAO Thursday, August 13, 2009 3:00 AM
    Tuesday, August 11, 2009 6:10 PM
  • Hi,

     

     

    Thank you Paul for pointing the problem out. I am sorry Fontano, I have misunderstood your problem.

    If I understand you correctly this time, the behavior you got is sometime by design.

    As a workaround, we can use System.Drawing.Point to store value of the AutoScrollPosition of the Panel as Paul recommended. However, Panel.AutoScrollPositon.X and Panel.AutoScrollPositon.Y contain negative values, we need to use Math.Abs to obtain a positive value.

    For example:

     

    panel1.AutoScrollPosition = new Point(Math.Abs(panel1.AutoScrollPosition.X), Math.Abs(CurrentPoint.Y));

     

    This link has a detail description of scroll position problem in an auto-scrollable Panel

    http://support.microsoft.com/default.aspx/kb/829417

     

    Regards,

    Zhe Zhao

    • Proposed as answer by Paul Diston Wednesday, August 12, 2009 6:00 AM
    • Marked as answer by ZHE ZHAO Thursday, August 13, 2009 1:57 AM
    Wednesday, August 12, 2009 5:55 AM