Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态在第一个控件之后添加第二个控件_C#_Winforms_Dynamic Controls - Fatal编程技术网

C# 动态在第一个控件之后添加第二个控件

C# 动态在第一个控件之后添加第二个控件,c#,winforms,dynamic-controls,C#,Winforms,Dynamic Controls,在c#中,我的flowlayoutpanel上有一个动态控件。我想要另一个控件被放置在第一个控件之后,只需点击一个按钮 我这样做的方法是将控件的高度存储在全局变量中,然后每次添加控件时,都向其添加另一个高度。这为您提供了每次向下移动位置以使控件显示在下面所需的量 然后在按钮单击事件上,我将创建一个新控件,并使用新的drawing.point设置位置,然后将X参数设置为控件的当前X位置,然后将Y参数设置为全局变量 int glHeightAccumalator = Control.Height;

在c#中,我的flowlayoutpanel上有一个动态控件。我想要另一个控件被放置在第一个控件之后,只需点击一个按钮

我这样做的方法是将控件的高度存储在全局变量中,然后每次添加控件时,都向其添加另一个高度。这为您提供了每次向下移动位置以使控件显示在下面所需的量

然后在按钮单击事件上,我将创建一个新控件,并使用新的drawing.point设置位置,然后将X参数设置为控件的当前X位置,然后将Y参数设置为全局变量

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;

请出示一些代码。你试过什么?