2011-02-24 7 views
0

요구 사항 : 나는 C#으로 작성된 Windows 응용 프로그램을 가지고 있으며 확인란을 선택하면 검색된 파일이 하위 폴더에 복사되는 것보다 확인란에 추가하려고합니다. 우편 번호에.C# checkBox_CheckedChanged 다른 파일에서 참조하기

문제 : 나는 오류가 다른 페이지 SearchProcess.cs에 MainForm.cs에서 addzipdir_checkBox.Equals (true)를 참조하면는 "addzipdir_checkBox이 현재 컨텍스트에 존재하지 않습니다." checkBox_CheckedChanged occurence를 참조하는 적절한 방법은 무엇입니까? 다음은 오류를 생성 SearchProcess.cs에 코드의

private void addzipdir_checkBox_CheckedChanged(object sender, EventArgs e) 
    { 
     if (addzipdir_checkBox.Equals(true)) 
     { 
      Log("Organize files by zip code."); 
     } 

     if (addzipdir_checkBox.Equals(false)) 
     { 
      Log("Don't Organize files by zip code."); 
     } 
    } 

:

여기 MainForm.cs의 코드입니다

 if (addzipdir_checkBox.Equals(true)) 
     { 

      // adds the given lead's agentid and zip code to the targetpath string 
      string targetzipdir = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP; 

      // If the given lead's zip code subdirectory doesn't exist, create it. 
      if (!Directory.Exists(targetzipdir)) 
      { 
       Directory.CreateDirectory(targetzipdir); 
      } 

      targetFileAndPath = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP + "\\" + fullFileName; 
     } // end if addzipdir_checkBox.Equals(true) 
+2

당신 변수를 참조 할 수 있으며 다른 형식의 컨트롤은 참조 할 수 없습니다. –

+0

줄을 추가했습니다. bool addzipdirectory_checkbox = 1; 첫 번째 if 문 아래에서 if (addzipdir_checkBox.Equals (true))하지만 여전히 searchprocess.cs 파일에서 참조 할 수 없습니다. 이 m_form.Invoke (m_form.m_DelegateAddString, 새 개체 [] 상태에서 검색 : "+ m_sc.get_State()});) 같은 가져 오기 문을 사용해야합니다. 또는 if (m_sc.get_SearchAND() == true) { m_form.Invoke (m_form.m_DelegateAddString, new Object [] {모두 검색}}); } 또는 Utility.Properties.Settings.Default에서 가져 오십시오. 지역? –

답변

0

난 당신이 바로 변수를 클릭하고 클릭하면이 변수가 참조하는 위치를 찾기 위해 많은 쉽게 "정의로 이동"것을 발견했다. MainForm을 통해 호출 된 다른 변수를 마우스 오른쪽 버튼으로 클릭하면 SearchCriteria 파일을 통해 모두 호출된다는 것을 알았습니다. SearchCriteria.cs 파일을 통해 MainForm.cs 파일에서 참조되는 addzipdir_checkbox 값을 가져 와서 SearchProcess.cs 파일에서 호출해야했습니다.

public class SearchCriteria 
{ 
    private String Corp; 
    private String OrderNumber; 
    private String Campaign; 
    private String City; 
    private String State; 
    private String Zip; 
    private String SourcePath; 
    private String TargetPath; 
    private bool SearchOR; 
    private bool SearchAND; 
    private bool addzipdirectory_checkBox; 

    public SearchCriteria() 
    { 
    } 

    public SearchCriteria(String Corp, 
          String OrderNumber, 
          String Campaign, 
          String City, 
          String State, 
          String Zip, 
          String SourcePath, 
          String TargetPath, 
          bool SearchOR, 
          bool SearchAND, 
          bool addzipdirectory_checkBox)    
    { 
     this.Corp = Corp; 
     this.OrderNumber = OrderNumber; 
     this.Campaign = Campaign; 
     this.City = City; 
     this.State = State; 
     this.Zip = Zip; 
     this.SourcePath = SourcePath; 
     this.TargetPath = TargetPath; 
     this.SearchOR = SearchOR; 
     this.SearchAND = SearchAND; 
     this.addzipdirectory_checkBox = addzipdirectory_checkBox; 
    } 
    public bool get_addzipdir_checkBox() 
    { 
     return addzipdirectory_checkBox; 
    } 
    public void set_addzipdir_checkBox(bool x) 
    { 
     addzipdirectory_checkBox = x; 
    } 
}    

가 여기에 Searchprocess.cs 파일에 내 코드입니다 :

다음은 SearchCriteria.cs 파일에 내 코드입니다 있도록 어딘가에 변수를 업데이트해야합니다 확인란을 선택 생각

  // Copy the file if ANY of the search criteria have been met 
      if (found) 
      { 

       m_form.Invoke(m_form.m_DelegateAddString, new Object[] {"FOUND: Order_No: " + Order_No + 
                     " barcode: " + barcode + 
                     " MailerCode: " + MailerCode + 
                     " AgentID: " + AgentID + 
                     " City: " + City + 
                     " State: " + State + 
                     " ZIP: " + ZIP}); 


       //passes values to TransferFile 
       TransferFile(directory, barcode, AgentID, ZIP); 
      } 
     } // end for that finds each matching record 

    } 

    // find and copy the file to the target directory string ZIP 
    private void TransferFile(string sourceDir, string filename, string AgentID, string ZIP) 
    { 
     string fullFileName = filename + ".pdf"; 
     string fullFileNameAndPath = sourceDir + "\\" + fullFileName; 
     string targetFileAndPath; 

     if (m_sc.get_addzipdir_checkBox()==true) 
     { 

      // adds the given lead's agentid and zip code to the targetpath string 
      string targetzipdir = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP; 

      // If the given lead's zip code subdirectory doesn't exist, create it. 
      if (!Directory.Exists(targetzipdir)) 
      { 
       Directory.CreateDirectory(targetzipdir); 
      } 

      targetFileAndPath = m_sc.get_TargetPath() + "\\" + AgentID + "\\" + ZIP + "\\" + fullFileName; 
     } // end if addzipdir_checkBox.Equals(true) 
0
  • 당신은 확실히 addzipdir_checkBox는 공개 할 필요가있다. 이 경우 양식 편집기를 사용하여 addzipdir_Checkbox를 선택하고 속성 표 '수정 자'항목을 public 또는 internal으로 변경해야합니다.

  • 는 그런 다음,이 양식의 인스턴스를 참조 할 수있는 방법을 찾기 위해이 같은 뭔가가 필요 :

    () (참 myForm.addzipdir_checkBox.Equals) { ... 경우 ... 은}

+0

응답 해 주셔서 감사합니다! addZipdir_Checkbox에 대한 수정 자 속성을 public으로 만들었지 만 m_form.addzipdir_checkbox() = 1)을 추가하면 MainForm에 addzipdir_checkbox 및 확장 메서드 addzipdir_Checkbox에 대한 정의가 포함되어 있지 않습니다 (사용 지시문이나 어셈블리 참조가 누락 되었습니까? ?). 나는 또한 퍼팅 시도했다 (m_form.get_addzipdir_checkbox() = 1) 및 그 같은 오류가 발생했습니다. –

+0

My MainForm 파일에서 다음을 사용하고 있습니다 : using System; 시스템 사용.ComponentModel; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; ---------------------------------- 그리고 SearchProcess는 다음을 사용합니다 : using System; using System.Windows.Forms; using System.Threading; Com.StellmanGreene.CSVReader를 사용하여; System.IO 사용; using System.Data; using System.Collections.Generic; –

+0

@Brian - 체크 박스 유형은 무엇입니까? 어쩌면 당신은 'if (m_form.addzipdir_checkbox.Checked) {...}'와 같은 것을하고 싶습니까? –

관련 문제