2013-06-22 2 views

답변

1

private void frm_SystemLog_Load(object sender, EventArgs e) 
    { 

     Log frm_LoginMenu = new Log(); 
     frm_LoginMenu.ShowDialog(); 
     if(frm_LoginMenu.ShowDialog() == DialogResult.OK) 
     { 
      this.TextBoxValue = frm_LoginMenu.MyValue; 
     } 

    } 
을 당신의 frm_SystemLog 형태로 이벤트 다음

private void button2_Click(object sender, EventArgs e) 
    { 
     MyValue = "SomeValue"; 
     //no need to close ,dialogresult will do it... 

    } 

을 클릭

이렇게하면 문제가 해결됩니다.

+0

frm_SystemLog에 로그 양식을 다시 불러올 때 트리거 변수 원인을 만들어야하지만 코드가 유용했습니다. –

0

frm_SystemLog.TextBoxValue ISN '

public partial class frm_SystemLog : Form 
{ 
    public frm_SystemLog() 
    { 
     InitializeComponent(); 
    } 

    public string TextBoxValue 
    { 
     // suppose to get value from other forms 
     get { return this.textBox1.Text; } 
     set { textBox1.Text = value; } 
    } 

    private void frm_SystemLog_Load(object sender, EventArgs e) 
    { 
     Log frm_LoginMenu = new Log(); 
     frm_LoginMenu.ShowDialog(); 
    } 
} 

이 내 하위 양식입니다 : 이것은 내 주요 형태

an object reference is required for the non-static field

입니다 : 어떤 이유로 하위 형태 나에게 오류를주고있다 다른 클래스에 있기 때문에 button2_Click에서 액세스 할 수 없습니다.

다음 DialogResult를 선택하고 단추 2에서 다음 확인을 로 설정 로그 형태의 당신의 단추 2의 속성에서 다음
//in log form 
public String MyValue{get;set;} 

에 액세스하는 값을 설정하면 로그 형태의 속성을 만들어야합니다
+0

난 그게 문제였다 그림. .. 그것을 평가하지만, 나는 해결책을 요구하고 있었다. –

0

현재 클래스의 인스턴스가 아닌 상위 폼 클래스의 개체를 참조하려고합니다. 이 경우 참조 할 수있는 유일한 객체는 정적 객체이므로 오류가 발생하고 있습니다.

부모 양식의 인스턴스에 대한 실제 참조가 필요합니다. 다음과 같이 Log 클래스를 변경합니다

public partial class Log : Form 
{ 
    private frm_SystemLog parentForm; 

    public Log(frm_SystemLog parentForm) 
    { 
     InitializeComponent(); 

     this.parentForm = parentForm; 
    } 
    ... 
    ... 

그런 다음 사용하여 하위 양식을 인스턴스화 :

Log frm_LoginMenu = new Log(this); 

읽기 "Understanding Classes, Methods, and Properties in C#" 자세한 내용은, 특히 :

There are two kinds of methods in C#. They are:

  • Instance Method
  • Static Method

Instance Methods are methods declared outside the main method and can be accessed only by creating an object of the corresponding class.

Class methods also are declared outside the main method but can be accessed without creating an object of the class. They should be declared with the keyword static and can be accessed using the classname.methodname syntax.

+0

나는 많은 것을 배웠지 만, 그 방향이 내 문제를 해결하지 못했다. –

+1

이것은 꽤 기본적인 물건입니다. @Henryyottabyte. 수정할 코드를주었습니다. 어떻게 * 정확하게 * 당신의 문제를 해결하지 못했습니까? –

관련 문제