Вопрос

In c# I have a dynamic control on my flowlayoutpanel. I want another control to be placed exactly after the 1st control on the click of a button.

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

Решение

The way i would do this is to store the height of the control in a global variable then each time you add a control add another lot of its height to it. This gives you the amount that you need to move the location down by each time to get the control to appear below.

Then on the button click event i would create a new control and set the location by using a New drawing.point and setting the X parameter to the current X location of the control and then the Y parameter to the global variable.

int glHeightAccumalator = Control.Height; ' I would set this on the form load when you already have your first control in the Flow Layout Panel.

''Button Click Event

Control ctrl = new Control();
ctrl.Location = Drawing.Point(ctrl.Location.X, glHeightAccumalator);
FlowLayoutPanel.Controls.Add(ctrl);
glHeightAccumalator += ctrl.Height;
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top