0

There are some user controls in a FlowLayoutPanel. each user controls have a label for its user control info.

the FlowLayoutPanel properties:

AutoScroll = true
WrapContents = false

by clicking the user control (background) the label info gets updated. but if you have many user controls in FlowLayoutPanel and with being auto scroll property, the scroll goes wrong when clicking items, looks like the top of scroll stick where you click the user control.

How to fix this scroll problem?


OK, here is a demo GIF file, first part of it demonstrate that scroll works good without clicking items (which changes the value) second part demonstrate that scroll sticks somewhere down with clicking an item (which changes a value).

FlowLayoutPanel problem with inner items changes

  • I should say that the FlowLayoutPanel.PerformLayout() does not work by the inner item of FlowLayoutPanel.

*** Even clicking on area in the FlowLayoutPanel also cause the problem! I didn't test it.

Mohammad Eskandari
  • 221
  • 1
  • 3
  • 8
  • After reading your question a couple of times, I'm still not sure what's happening. Can you explain a little more? Are the labels growing out of the user controls? Can you post a picture? – TaW Sep 20 '14 at 07:33
  • 1
    Cool demo! However I can't reproduce. Could you please add a Tag for the platform you are using (WPF or Winfiorms?!) I assume you are not doing funny things with Focus, SelectNextControl or the like? – TaW Sep 20 '14 at 11:29

1 Answers1

0

Solved!

The solution done by putting this code in the usercontrol code.

 private void ResControl_MouseDown(object sender, MouseEventArgs e)
 {
   this.Parent.Parent.Controls[0].Focus();
 }

It removes the focus on that FlowLayoutPanel.

  • note that there are two Parent in code because the form must be captured. Usercontrols are in a FlowLayoutPanel and FlowLayoutPanel is in a form.
Mohammad Eskandari
  • 221
  • 1
  • 3
  • 8