Tutorial :Repaint of panel



Question:

My problem is that I have a panel in panel. Inside i have the AutoScroll property set to true. When I open a new window this panel is scrolled to begining.

I do that, I save the position before open new window, and I set it after close it. It works but it jumps to the beginning and then back to my position.


Solution:1

The AutoScrollPosition property is a bit funny. When you read it, it will return the current scroll offset, but when you assign it you will need to invert the values:

private static Point GetAutoScrollPosition(Panel panel)  {      return panel.AutoScrollPosition;  }    private static void SetAutoScrollPosition(Panel panel, Point position)  {      panel.AutoScrollPosition = new Point(-position.X, -position.Y);  }  

Now you can retrieve the current position and set it like so:

Point pos = GetAutoScrollPosition(myPanel);  SetAutoScrollPosition(myPanel, pos);  


Solution:2

Have you tried setting autoscroll to false?


Solution:3

I do something lik You wrote

_scrollPozition = -(pnlMain.AutoScrollPosition.Y); DialogResult result = MessageBox.Show("Delete: ", MessageBoxButtons.YesNo); dgvClendar.Focus();

private void pnlMain_Paint(object sender, PaintEventArgs e) {

        if (pnlMain.AutoScrollPosition.Y == 0)          {              pnlMain.AutoScrollPosition = new Point(0, _scrollPozition);              _scrollPozition = 0;          }      }  

on paint it is set, but if you look everything is moved for a moment. I need to block this scroll to begin, or block painting, and repaint after scroll to current position.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »