2011-08-24 3 views
0

childform에서 parentform으로 부울 플래그를 전달하는 데 문제가 있습니다.childform에서 parent로 플래그를 전달하는 방법은 무엇입니까?

나는 예를 들어 childform하는 parentform에서 그것을 전달하는 방법을 알고

mainform에

: childform에

Camera settings = new Camera(this.fullPath3); 
settings.ShowDialog(); 

:

public partial class Camera : Form 
    { 
     //Zmienne przekazywane - sciezka do zapisu wzorca, 
     string _fullPath3; 

...

public Camera(string fullPath3) 
    { 

     InitializeComponent(); 
     _fullPath3 = fullPath3; 

및 그 작품 ing. 내 childform에서 반환으로 bool 플래그를 추가하는 방법? 그런

뭔가 : childform에

: mainform에

public Camera(string fullPath3, bool flag) 

:

Camera settings = new Camera(this.fullPath3,this.flag); 
    settings.ShowDialog(); 
    if (flag==true) text2.text="OK!"; 
+0

자녀 양식에 이벤트를 작성하고 상위 양식의 해당 이벤트에 연결하는 것이 어떨까요? 이렇게하면 부모 양식으로 정보를 다시 전달할 수 있습니다. – Jethro

+0

이벤트를 사용할 수 있습니다. [Heres] (http://stackoverflow.com/questions/6382750/adding-an-event-handler-for-a-control-in-child-form-from-parent-form-in-c/6382869#6382869) 내 예제 – Reniuz

답변

1

단순 Camera는 양식, 그래서 그냥 여기에 공용 속성을 추가 할 수 있습니다.

public class Camera : Form 
{ 
    private string _fullPath3; 
    private bool flag; 
    public Camera(string fullPath3) 
    { 

     InitializeComponent(); 
     _fullPath3 = fullPath3; 
    } 

    // set flag to something somewhere 
    public bool Flag{ get{ return flag; } } 

} 

지금 단지 :

Camera settings = new Camera(this.fullPath3); 
settings.ShowDialog(); 
if (settings.Flag) text2.text="OK!"; 

ShowDialog가 정지 실행을 기억!

+0

카메라 설정 = "this.flag"가없는 새 카메라 (this.fullPath3, this.flag)가 작동 함 -> 카메라 설정 = 새 카메라 (this.fullPath3) Tnx;) – Elfoc

+0

@Elfoc - 예, 코드를 복사했습니다. ctor에서 제거해야합니다. 답변이 업데이트되었습니다. – Jamiec

0

은 그냥 Camera 형태로 내부 또는 공공 재산을 구현, 그 안에서이 속성을 설정 . 이 같은

뭔가 :

Camera settings = new Camera(this.fullPath3,this.flag); 
    settings.ShowDialog(); 
    if (settings.Flag) text2.text="OK!"; 
관련 문제