Is there a better way to handle these controls, Fl

2019-09-06 03:38发布

问题:

Currently I am using a FlowLayoutPanel to display my custom controls, it has worked well so far but now seems to be lacking when I want to change the layout of the controls per user requests. I have been trying to find a way to change the WrapContents attribute of the FlowLayoutPanel to re-apply the layout of the panel with the new attribute but keep falling short.

So I was wondering if there was a completely different solution.

I have two types of controls I want to display to the user, banners and indicators. For every banner there are 24-48 indicators along with it (They represent electrical boards). I want to display these controls to the user in two ways. First in one long list (which FlowLayoutPanel did pretty well with WrapContents = false) and second in columns of lists, one per banner (So each column would be headed by a banner with its indicators beneath.)

Below is a picture of how FlowLayoutPanel did at this task. For the first method of one long list it was simple, just set WrapContents = false and everything would line up in one nice long list. The problem I was having was for the second method; more specifically getting the FlowLayoutPanel to switch between the two methods of displaying the forms. As you can see with WrapContents set to true the LayoutEngine creates columns, but overflows them to the next column. (I never tried to fix this, I am still stuck on how to reapply the layout after setting WrapContents on a FlowLayoutPanel)

So my question is, is there a better solution to my problem.

  • Is there a layout panel that I can display my controls in the two manners described?
  • Also, easily switch between the two at the users request (by means of a checkbox/button that would redraw/relayout the controls)?

回答1:

Is there a layout panel that I can display my controls in the two manners described?

FlowLayoutPanel is the panel you are looking for, the problem you have is because your banner and indicator are not associated. so FlowLayoutPanel treat each of them as an individual control, hence the overflow you have observed.

As I pointed out in my comments, you need an extra user control to combine Banner and all its possible Indicators, and add this new control into the FlowLayoutPanel instead.

Also, easily switch between the two at the users request (by means of a checkbox/button that would redraw/relayout the controls)?

When you done the first part, you can then switch layout by setting FlowLayoutPanel's FlowDirection to TopDown or LeftToRight (with WrapContents set as False).