其中一个窗体代码 Form3
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form3 : Form
{
public Counter c1
{
get
{
Counter c1 = new Counter();
c1.dataok = this.intok;
c1.datapass = this.intpass;
c1.datano = this.intno;
c1.datatotal = this.inttotal;
return c1;
}
set
{
Counter c1 = new Counter();
c1.dataok = this.intok;
c1.datapass = this.intpass;
c1.datano = this.intno;
c1.datatotal = this.inttotal;
}
}
//设置三个对应认可度的变量并赋初值
public int intok = 0;
public int intpass = 0;
public int intno = 0;
public int inttotal = 0;
public Form3()
{
InitializeComponent();
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton1.Checked)
{
this.intok = this.intok + 1;
}
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton2.Checked)
{
this.intpass = this.intpass + 1;
}
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
if (this.radioButton3.Checked)
{
this.intno = this.intno + 1;
}
}
private void Form3_Load(object sender, EventArgs e)
{
//默认初始未选中
this.radioButton1.Checked = false;
this.radioButton2.Checked = false;
this.radioButton3.Checked = false;
}
//当三个按钮有变化时自加
private void button1_Click(object sender, EventArgs e)
{
//提交时累加 并关闭调查窗口 显示窗口一
if (radioButton1.Checked)
c1.dataok++;
if (radioButton2.Checked)
c1.datapass++;
if (radioButton3.Checked)
c1.datano++;
//如果未选择过任何一个按钮 总数不自加
if (intok != 0 || intno != 0 || intpass != 0)
c1.datatotal++;
this.Hide();
Form1 frm1 = new Form1();
frm1.Show();
}
}
}
另一个窗体代码 Form4
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//用户选择退出时 关闭此窗口 回到窗口一
this.Close();
Form1 frm1 = new Form1();
frm1.Show();
}
private void Form4_Load(object sender, EventArgs e)
{
//页面加载显示
this.label5.Text = c1.datatotal.ToString();
this.label2.Text = c1.dataok.ToString();
this.label3.Text = c1.datapass.ToString();
this.label4.Text = c1.datano.ToString();
}
private void label5_Click(object sender, EventArgs e)
{
}
}
}
Form3中的类已经实例化,Form4引用后c1不能识别,是什么问题呢