2017-05-07 1 views
-1

저는 아이들을위한 수학 연습 프로그램을 만들어야합니다. 그들은 1 개의 조작과 그 숫자가 가질 자릿수 (1, 2 또는 3 자릿수)를 선택할 수 있어야합니다. 그런 다음 아이들이 선택한 것에 따라 무작위로 10 개의 질문을 내야합니다. 그런 다음 퀴즈를 마친 후에는 결과와 질문을 표시해야합니다.C에서 form1과 form2 사이에 데이터 전달

form1, operation 및 number of numbers (1 (*) 2 (/) 3. (+) 4 (-))가 할당 된 두 가지 선택 항목이 있습니다. 내가해야 할 일은 질문을 생성하고 표시 할 작업 번호와 자리 숫자를 form2에 전달하는 것뿐입니다. 여기에 거의 알몸을 Form2의

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace FinalProject 
{ 
public partial class Form1 : Form 
{ 
    public static int operation = 0; 
    public static int digits = 0; 

    public Form1() 
    { 
     InitializeComponent(); 
    } 
    // this is to make sure only one box is checked for both selections. Starts here 
    private void label1_Click(object sender, EventArgs e) 
    { 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 

    } 

    private void MulCB_CheckedChanged(object sender, EventArgs e) 
    { 


     if (MulCB.Checked == true) 
     { 
      operation = 1; 
      DivCB.Checked = false; 
      AddCB.Checked = false; 
      SubCB.Checked = false; 
     } 
    } 

    private void DivCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (DivCB.Checked == true) 
     { 
      operation = 2; 
      MulCB.Checked = false; 
      AddCB.Checked = false; 
      SubCB.Checked = false; 
     } 
    } 

    private void AddCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (AddCB.Checked == true) 
     { 
      operation = 3; 
      DivCB.Checked = false; 
      SubCB.Checked = false; 
      MulCB.Checked = false; 
     } 
    } 

    private void SubCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (SubCB.Checked == true) 
     { 
      operation = 4; 
      DivCB.Checked = false; 
      AddCB.Checked = false; 
      MulCB.Checked = false; 
     } 
    } 

    private void oneDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if(oneDCB.Checked == true) 
     { 
      digits = 1; 
      twoDCB.Checked = false; 
      threeDCB.Checked = false; 
     } 
    } 

    private void twoDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (twoDCB.Checked == true) 
     { 
      digits = 2; 
      oneDCB.Checked = false; 
      threeDCB.Checked = false; 
     } 
    } 

    private void threeDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (threeDCB.Checked == true) 
     { 
      digits = 3; 
      oneDCB.Checked = false; 
      twoDCB.Checked = false; 
     } 
    } 
    private void button8_Click(object sender, EventArgs e) 
    { 
     // operations: 1. (*) 2. (/) 3. (+) 4. (-) 
     // digits are as number indicates. 



     // Second window popup. 
     Form2 settingsForm = new Form2(); 
     settingsForm.Show(); 
    } 
} 
} 

:

여기에 지금까지 Form1의 내 코드입니다.

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace FinalProject 
{ 

public partial class Form2 : Form 
{ 


    public Form2() 
    { 
     InitializeComponent(); 
    } 

    private void FinishedBtn_Click(object sender, EventArgs e) 
    { 


    } 
} 

}

+0

안녕 살! 귀하의 질문을 편집하십시오 : 1. 코드를 적게 포함하고, 2. 무엇을 시도했는지, 무엇이 효과가 있었는지, 그리고 효과가 없었는지, 3. 구체적으로 보내고 받기를 원하는 정보, 특별히 도움이 필요한 정보를 말하십시오. 와? 또한, @DourHighArch가 아마도이 질문이 중복 된 것이라고 생각합니다. –

+0

원하는 경우 [도움말 센터] (https://stackoverflow.com/help/how-to-ask)로 가서보다 적절한 질문을하는 방법에 대한 도움말을 참조하십시오. 행운을 빌어 요, 고마워요! –

+0

변수를 잘못된 양식에 넣습니다. 'public static int operation = 0;public static int digits = 0;'은 form2가 아닌 1에 있어야합니다. 새로운 인스턴스를 호출 한 후에 설정할 수있는 Form의 속성입니다 (Form2 settingsForm = new Form2(); – rudib

답변

0

이 작동하지 않을 수 있습니다. 코드에 주석이 있습니다.

워크 플로는 Form2 클래스의 새 인스턴스를 만들고 두 개의 공용 변수를 설정합니다. 공개는 수업 외부에서 액세스 할 수 있음을 의미합니다 (원하는 경우 here 참조). 그런 다음 Show() 메서드가 호출되고 Form이 나타납니다. Form2 코드에서 공용 변수는 이전에 지정된 값을 가지며 사용할 수 있습니다.

를 Form1 :

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace FinalProject 
{ 
public partial class Form1 : Form 
{  
    public Form1() 
    { 
     InitializeComponent(); 
    } 
    // this is to make sure only one box is checked for both selections. Starts here 
    private void label1_Click(object sender, EventArgs e) 
    { 

    } 

    private void button2_Click(object sender, EventArgs e) 
    { 

    } 

    private void MulCB_CheckedChanged(object sender, EventArgs e) 
    { 


     if (MulCB.Checked == true) 
     { 
      operation = 1; 
      DivCB.Checked = false; 
      AddCB.Checked = false; 
      SubCB.Checked = false; 
     } 
    } 

    private void DivCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (DivCB.Checked == true) 
     { 
      operation = 2; 
      MulCB.Checked = false; 
      AddCB.Checked = false; 
      SubCB.Checked = false; 
     } 
    } 

    private void AddCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (AddCB.Checked == true) 
     { 
      operation = 3; 
      DivCB.Checked = false; 
      SubCB.Checked = false; 
      MulCB.Checked = false; 
     } 
    } 

    private void SubCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (SubCB.Checked == true) 
     { 
      operation = 4; 
      DivCB.Checked = false; 
      AddCB.Checked = false; 
      MulCB.Checked = false; 
     } 
    } 

    private void oneDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if(oneDCB.Checked == true) 
     { 
      digits = 1; 
      twoDCB.Checked = false; 
      threeDCB.Checked = false; 
     } 
    } 

    private void twoDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (twoDCB.Checked == true) 
     { 
      digits = 2; 
      oneDCB.Checked = false; 
      threeDCB.Checked = false; 
     } 
    } 

    private void threeDCB_CheckedChanged(object sender, EventArgs e) 
    { 
     if (threeDCB.Checked == true) 
     { 
      digits = 3; 
      oneDCB.Checked = false; 
      twoDCB.Checked = false; 
     } 
    } 
    private void button8_Click(object sender, EventArgs e) 
    { 
     // operations: 1. (*) 2. (/) 3. (+) 4. (-) 
     // digits are as number indicates. 



     // Second window popup. 
     // it's the question form, right? 
     Form2 questionForm = new Form2(); 
     //"Write" your settings in the other form's variables 
     //You will have to write code that finds out which checkbox is which number! For now its fixed. 
     questionForm.operation = 2; 
     questionForm.digits = 1; 
     questionForm.Show(); 
     //Hide Form1 
     this.Hide(); 
    } 
} 
} 

형식 2 :

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace FinalProject 
{ 

public partial class Form2 : Form 
{ 
    public static int operation; 
    public static int digits; 


    public Form2() 
    { 
     InitializeComponent(); 

    } 

    //do NOT paste this. It can be added by creating an event handler 
    // you also might not need this, but this method is called when this Form appears. It's an example. 
    // https://msdn.microsoft.com/en-us/library/zwwsdtbk(v=vs.80).aspx 
    private void Form2_Load(object sender, EventArgs e) 
    { 
     //here you can use your variables for example (also anywhere within this class!) 
     //e.g. 
     Textbox1.Text = (string)operation; 
    } 

    private void FinishedBtn_Click(object sender, EventArgs e) 
    { 


    } 
} 
} 
관련 문제