Вопрос

A Windows Form application displays a main form. This main form contains few different Panel controls. Depending on some condition in that form one of these Panel controls is to be made active while the others are made invisible.

First panel contains a DataGridview, Second panel contains controls to display the details of the DataGridView. On Add button click (or) On selecting a record in DataGridView the second panel should be visible. I am using Visible property to show and hide panel, but the gap is showing there as shown in screenshot.

Please suggest best way to handle this.

enter image description here

enter image description here

Это было полезно?

Решение

You just need the panels to share the same location. You probably don't want to do that at design-time, as it makes future maintenance of the form difficult.

In the Form.Load event, set the location of the bottom panel to match the location of the top panel.

PanelDetails.Location = PanelDataGrid.Location;

Now when you hide one and show the other, they'll appear in the same place.

Другие советы

The smartest way is to keep the panels separate at the designer. This way any editings made on them can be done more easily, and all actual objects can be seen immediately.

In the designer, set the other panels' Visible properties to False, excep the first one on the top.

Form.Load:

  • Set all the other panels' locations to match the location of the first panel (on the top)

  • Set the form's height to match a desired height, which fits to your heightest panel

  • Use the buttons to toggle panels visibility (and possibly the form height too)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top