2012-11-29 4 views
1

가능한 중복 :
Calling a method on another form in C#다른 폼에서 메소드를 호출하려면 어떻게해야합니까? C#을

내가 내 프로그램의 두 형태가있다. form1에서 버튼을 클릭 할 때 form2 클래스의 메소드를 호출 할 수있는 방법이 있습니까?

이것은 내가 시도한 것입니다. clear_grid는() 나는 양식 2 (이름 GameForm)에있는 방법이이 작동하지 않습니다 물론 1

private void yesButton_Click(object sender, EventArgs e) 
{ 
    this.Hide(); 
    GameForm.ActiveForm.Invoke(clear_grid()); 
} 

형태의 버튼에 대한 이벤트 리스너입니다. 비슷한 방법이 있습니까? 이 같은

+0

[C#의 또 다른 형태에있어서 호출]의 중복 가능성 (http://stackoverflow.com/questions/837788/calling-a-method-on-another-form-in-c-sharp) http://stackoverflow.com/questions/12890754/call-a-method-from-another-form 또는 http://stackoverflow.com/questions/13442891/calling-a-method-in-another-form-c -sharp –

답변

0

시도 뭔가 : - GameForm 만약

(Form1)this.Parent.RefreshTable(); 
3

는 두 번째 폼 클래스와 clear_grid의 인스턴스 다음, 단순히 메소드를 호출에 무슨 잘못 공공 방법이다?

private void yesButton_Click(object sender, EventArgs e) 
{ 
    this.Hide(); 
    GameForm.clear_grid(); 
} 
+1

그래,이 작업을 수행했습니다. GameForm gf = (ConnectFour.GameForm) GameForm.ActiveForm; gf.clear_grid(); 나는 이것을 캐스팅 할 수 있는지 몰랐다. 그래서 나는 그 방법을 호출 할 수 없다고 생각했다! 감사 :) – Bernice

관련 문제