Panel repainting

My problem is that I have a panel on a panel. Inside the property is AutoScrollset to true. When I open a new window, this panel scrolls to the beginning.

I do this, I keep the position before opening a new window, and I set it after closing. It works, but it jumps to the beginning, and then returns to my position.

+3
source share
3 answers

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 get the current position and set it like this:

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

autoscroll false?

0

-

_scrollPozition = - (pnlMain.AutoScrollPosition.Y); Result DialogResult = 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;
        }
    }

it is installed on the paint, but if you look, everything is moved for a moment. I need to lock this scroll to start, or block drawing, and redraw after scrolling to the current position.

0
source

Source: https://habr.com/ru/post/1712673/


All Articles