cmm
cmm

Reputation: 71

Prevent FlowLayoutPanel scrolling to updated Control

I have an application which uses a FlowLayoutPanel with a lot of Custom UserControls in it. The Custom UserControls contains a Label.

The problem: When the Label is updated the FlowLayoutPanel automatically scrolls it into view (Similar to the FlowLayoutPanel.ScrollControlIntoView() function).

This is the code snippet that makes the FlowLayoutPanel Scroll:

private void DownloadChanged(Object sender, DownloadProgressChangedEventArgs e)
{
        progressDownload.Value = e.ProgressPercentage;
        lblDownloaded.Text = e.BytesReceived.ToString() + " / " + e.TotalBytesToReceive.ToString();
}

I have been trying to find an event in the FlowLayoutPanel which I can intercept and stop it from scrolling when a child updates but I have not had any luck so far.

Is it possible to do this? If yes, how would I go about it? Thanks!

Upvotes: 3

Views: 1411

Answers (2)

Tim Ward
Tim Ward

Reputation: 71

If having scrolling issues when clicking on a control in a FlowlayoutPanel, use an inherited control:

public class MyFlowLayoutPanel : FlowLayoutPanel
{

    protected override System.Drawing.Point ScrollToControl(Control activeControl)
    {
        //return base.ScrollToControl(activeControl);
        return this.AutoScrollPosition;
    }
}

https://social.msdn.microsoft.com/Forums/windows/en-US/cb8ac2d4-5940-4ed2-9f09-22cd4b76032b/suppressing-automatic-scrolling-within-flowlayoutpanel-with-autoscroll?forum=winforms

Upvotes: 6

cmm
cmm

Reputation: 71

Setting the the Label's AutoSize Property to False seems to do the trick.

Read more here: Similar Issue

Upvotes: 1

Related Questions