如何更改面板中按钮的位置?

时间:2018-08-13 05:31:03

标签: c# windows winforms button panel

我正在尝试根据需要在面板中执行一些操作,并将现有添加的按钮的位置更改为新位置。

public class MyPanel : Panel
{   
   protected override OnPaint()
   {  
       // Added the controls.


       // Done some operations which needs the location change.


       // Changed the location of the buttons.

   }

 }

但是控件在面板中不可见。

只有在不更改位置的情况下,面板上才能正确显示控制。

请问任何人,为什么动态更改位置时面板上未显示控件?

1 个答案:

答案 0 :(得分:0)

将此添加到您的项目

Control board = panel1;

Button But = new Button()
{
     Size = new Size(size, size),
     Location = new Point(x, y),
     ....
};

board.Controls.Add(But);