C# UserControl.VerticalScroll.Value not being set

后端 未结 4 1412
野趣味
野趣味 2020-12-20 21:00

I\'ve got a chunk of C# code that is supposed to set VerticalScroll.Value within a class that inherits from UserControl. It gets called when any child object of the class c

4条回答
  •  無奈伤痛
    2020-12-20 21:30

    FlowLayoutPanel seems to be a different beast. The scroll bar does move down, but the value of flowlayoutpanel.VerticalScroll.Value remains at 0. I tried all above techniques plus some DoEvents() and Thread.Sleep(), even a timer which fully yielded before doing its next iteration. It all failed. I eventually discovered that DisplayRectangle.Y was instantly expressing the scroll change...

    private void PrintButton_Click(object sender, EventArgs e)
    {
        FlowLayoutPanel flp = TheBuildFlowLayoutPanel;
        List printPics = new List();
        int printLastY = 100;
        flp.VerticalScroll.Value = 0;
        while (flp.DisplayRectangle.Y < printLastY) // DisplayRect.Y becomes successively more negative
        {
            Bitmap bmp = new Bitmap(flp.Width, flp.Bounds.Height);
            printPics.Add(bmp);
            flp.DrawToBitmap(bmp, flp.ClientRectangle);
            printLastY = flp.DisplayRectangle.Y;
            flp.VerticalScroll.Value = Math.Min(flp.VerticalScroll.Maximum, flp.VerticalScroll.Value + flp.Height);
        }
    
        flp.VerticalScroll.Value = 0;
        for (int i = 0; i < printPics.Count; i++)
        {
            printPics[i].Save("C:\\Temp" + i.ToString() + ".bmp");
        }
    }
    

提交回复
热议问题