, 다음 ...
먼저 새로운 Button
객체를 생성 할 수 있습니다.
Button newButton = new Button();
그런 다음 사용하여 해당 함수 내 양식에 추가 : 사용자가 설정할 수
this.Controls.Add(newButton);
추가 속성 ...
newButton.Text = "Created Button";
newButton.Location = new Point(70,70);
newButton.Size = new Size(50, 100);
문제 실행중인 제품을 to는 Form_Load 이벤트에서 설정하려고 시도하는 것입니다.이 단계에서는 양식이 아직 존재하지 않고 버튼이 덮어 쓰기됩니다. 단추를 표시하려면 Shown
또는 Activated
이벤트에 대한 대리인이 필요합니다. 당신이 당신의 버튼을 생성하고 폼에 추가 어디 Form1
생성자 내부 예를 들어
,
public Form1()
{
InitializeComponent();
this.Shown += CreateButtonDelegate;
}
귀하의 실제 대표가이 같은 작동합니다.
private void CreateButtonDelegate(object sender, EventArgs e)
{
Button newButton= new Button();
this.Controls.Add(newButton);
newButton.Text = "Created Button";
newButton.Location = new Point(70,70);
newButton.Size = new Size(50, 100);
newButton.Location = new Point(20, 50);
}
이 윈폼입니다을 넣어? –
예 윈도우 폼 –
[동적으로 여러 버튼을 wpf 창에 추가 하시겠습니까?] (https://stackoverflow.com/questions/5929710/dynamically-add-multiple-buttons-to-wpf-window) –