About the Scroll bar of TableLayoutPanel

Source: Internet
Author: User

To simplify the layout of multiple controls, I used TableLayoutPanel in the project and set AutoScroll = true to implement the scroll bar function. QA found two problems during the test:

  1. When the content of TableLayoutPanel is too large and reaches a certain height, all the rows under it cannot be correctly displayed.
  2. Move the scroll bar with the mouse, switch to another form or program, reactivate the form, and the scroll bar is restored to its original state. The page remains at the top of the page.

After several Google attempts, I found out why:

  1. This is a bug in TableLayoutPanel. After testing, FlowLayoutPanel has the same problem. A foreigner encountered the same problem and provided a solution:

    While I didn't figure out why FlowLayoutPanel doesn't draw the items below a certain point, I found a workaround.
    Attach an event handler to Scroll, where you perform FlowLayoutPanel. Adjust mlayout () and it will draw the controls when you get to them.

  2. I thought it was a Microsoft Bug, but after reading the official reply, I only had workaround.
    Due to the fact that it is the previusly shipped behavior of FormAlways scroll the active control into view when the Form is activated, We will not be able to change this. We can consider a property to disable this functionality, but this feature will not make the Whidbey release. We will consider it for a future release.

The following code solves the problem for your reference:

 

Private void WFPanel_Load (object sender, EventArgs e)
{
FlpCharts. MouseWheel + = flpCharts_MouseWheel;
}

Private void flpCharts_MouseWheel (object sender, MouseEventArgs e)
{
FlpCharts. Focus ();
}

Private void flpCharts_Scroll (object sender, ScrollEventArgs e)
{
FlpCharts. datagmlayout ();
FlpCharts. Focus ();
}

 

The first and second lines of code of the Scroll event are designed to solve the two problems mentioned above. The MouseWheel event is used to handle the second problem. Because the MouseWheel event cannot be found in Designer, it is only manually registered in the Load event.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.