ZJY2369 2022-05-13 10:46 采纳率: 100%
浏览 74
已结题

对象引用对于非静态的字段、方法或属性是必须的所有fm2. () 都出现这个问题,form2里已经改成public了,求解


using System;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace Outcome_2
{
    public partial class fm1 : Form
    {
        public fm1()
        {
            InitializeComponent();
        }
        private string[] arrname;
        private string[] arrscore;
        private int judgename, judgescore = 0;
        private int number = 0;
        private float[] arrnumber;
        float max = 0, min = 0,sum = 0,average = 0;
        private float over, under = 0;


        private void btnsave_Click(object sender, EventArgs e)
        {
            string result = (MessageBox.Show("Are you sure to enter the grade and name?", "Please Confirm", MessageBoxButtons.OKCancel, MessageBoxIcon.Information)).ToString();
            if (result.Equals("OK"))
            {
                for (int i = 0; i < arrname.Length; i++)
                {
                    if (String.IsNullOrEmpty(txtname.Text))
                    {
                        lblnamehint.Text = "Name cannot be null";
                        lblscrhint.ForeColor = Color.Red;
                        judgename = 0;
                        break;
                    }
                    if (arrname[i] == txtname.Text)
                    {
                        lblnamehint.Text = "This name has already been entered";
                        lblnamehint.ForeColor = Color.Red;
                        judgename = 0;
                        break;
                    }
                    else
                    {
                        lblnamehint.Text = "√";
                        lblnamehint.ForeColor = Color.Green;
                        judgename = 1;
                    }
                }
            }
            string pattern_grade = @"^100(\.0*)?$|^\d{1,2}(\.[0-9]0*)?$|^\.[1-9]0*$";
            bool matchGrade = Regex.IsMatch(txtscore.Text, pattern_grade);
            if (matchGrade)
            {
                if (String.IsNullOrEmpty(txtscore.Text))
                {
                    lblscrhint.Text = "Score cannot be null";
                    lblscrhint.ForeColor = Color.Red;
                    judgescore = 0;
                }
                else
                {
                    lblscrhint.Text = "√";
                    lblscrhint.ForeColor = Color.Green;
                    judgescore = 1;
                }
            }
            else
            {
                lblscrhint.Text = "Please enter a score between 1 and 100";
                lblscrhint.ForeColor = Color.Red;
                judgescore = 0;
            }
            if (judgename == 1 && judgescore == 1)
            {
                arrname[number] = txtname.Text;
                arrscore[number] = txtscore.Text;
                fm2.rb.Text += txtname.Text + "     " + txtname.Text + "\n";
                number++;
                txtname.Text = "";
                txtscore.Text = "";
                for (int i = 0; i < number; i++)
                {
                    arrnumber[i] = float.Parse(arrscore[i].ToString());
                }
                max = arrnumber[0];
                min = arrnumber[0];
                sum = 0;
                for (int i = 0; i < number; i++)
                {

                    if (max < arrnumber[i])
                    {
                        max = arrnumber[i];
                    }

                    if (min > arrnumber[i])
                    {
                        min = arrnumber[i];
                    }

                    sum += arrnumber[i];

                    average = sum / number;

                }
                for (int i = 0; i < number; i++)
                {
                    if (arrnumber[i] >= average){
                        over++;
                    }
                    if (arrnumber[i] < average){
                        under++;
                    }
                }
                judgename = 0;
                judgescore = 0;
            }
            fm2.lblMax.Text = max.ToString();
            fm2.lblMin.Text = min.ToString();
            fm2.lblAvg.Text = average.ToString();
            fm2.lblSum.Text = sum.ToString();
        }

        private void fm1_Load(object sender, EventArgs e)
        {
            lbltime.Text = System.DateTime.Now.ToString();
            lbltime.Enabled = true;
            lblnamehint.Text = "Please input a name";
            lblscrhint.Text = "Please enter a score between 1~100";
            arrname = new string[200];
            arrscore = new string[200];
            arrnumber = new float[200];

        }

        private void Time_Tick(object sender, EventArgs e)
        {
            this.lbltime.Text = DateTime.Now.ToString();
        }

        private void fmdata(object sender, EventArgs e)
        {
            fm2 f2 = new fm2();
            f2.Show();
        }

        private void btnexit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to quit?","Warning",MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

       
    }
}

 

  • 写回答

2条回答 默认 最新

  • 於黾 2022-05-13 10:55
    关注

    fm2是类型
    f2才是它派生出来的实例
    你后续都应该是f2.属性,而不是fm2.属性

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 5月13日
  • 已采纳回答 5月13日
  • 修改了问题 5月13日
  • 赞助了问题酬金5元 5月13日
  • 展开全部

悬赏问题

  • ¥15 (标签-python|关键词-char)
  • ¥15 python+selenium,在新增时弹出了一个输入框
  • ¥15 苹果验机结果的api接口哪里有??单次调用1毛钱及以下。
  • ¥20 学生成绩管理系统设计
  • ¥15 来一个cc穿盾脚本开发者
  • ¥15 CST2023安装报错
  • ¥15 使用diffusionbert生成文字 结果是PAD和UNK怎么办
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频