C# 3.0 需要关于c中窗体继承的帮助吗

C# 3.0 需要关于c中窗体继承的帮助吗,c#-3.0,C# 3.0,我创建了一个表格,打印学生的平均成绩和成绩。我想将该窗体的属性继承到另一个窗体。如何实现这一目标?我是c语言的初学者,请帮忙。 这是我想要继承的形式 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Thread

我创建了一个表格,打印学生的平均成绩和成绩。我想将该窗体的属性继承到另一个窗体。如何实现这一目标?我是c语言的初学者,请帮忙。 这是我想要继承的形式

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 formstud
{
public partial class Form1 : Form
{
    public Form1()
    {
         InitializeComponent();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        String str = textBox1.Text;
        textBox2.Text = str;
    }

    private void button1_Click_1(object sender, EventArgs e)
    {
        int a, b, c, d;
        a = Convert.ToInt32(textBox3.Text);
        b = Convert.ToInt32(textBox4.Text);
        c = Convert.ToInt32(textBox5.Text);
        d = (a + b + c) / 3;
        if (d <= 50 && d >= 40)
        {
            label1.Text = "A";
        }
        else if (d >= 30 && d <= 40)
        {
            label1.Text = "B";
        }
        else
            label1.Text = "C";
        label7.Text = Convert.ToString(d);

    }

    private void label1_Click(object sender, EventArgs e)
    {

    }

    private void label7_Click(object sender, EventArgs e)
    {

    }
}

}

您需要执行以下操作:-

 public partial class Form1 : Form
    {
        public int PropertyA { get; set; }
        public int PropertyB { get; set; }


        public Form1()
        {
            InitializeComponent();
        }
    }

 public partial class Form2 : Form1
    {
        public Form2()
        {
            InitializeComponent();

            PropertyA = 1;
            PropertyB = 2;
        }
    }
关于这一点的快速解释。在表格1中,我创建了两个公共属性,PropertyA和PropertyB

然后我创建了Form2,只是这次我继承了Form1类,而不是Form。这使我可以访问PropertyA和PropertyB,而无需声明它们

这只是一个例子,你可以画一个接口,有点像合同,它建议我建立任何形式,我引用这个接口,它必须实现这些属性

public interface IProperties
    {
        int PropertyA { get; set; }
        int PropertyB { get; set; }
    }
现在,Form1和Form2可以如下所示:-

public partial class Form2 : Form, IProperties
{
    public Form2()
    {
        InitializeComponent();

    }

    public int PropertyA { get; set; }
    public int PropertyB { get; set; }
}

也许你会展示一些代码?你的页面上没有属性,请看我的例子。我得到的问题是通过创建类Student来用C实现以下算法。数据成员包括studFirstName、studLastName、studExam1、studExam2、studExam3和studAvg。创建一个stud对象并计算其最终成绩studAvg。然后创建一个继承自先前创建的学生类的继承类。该类应包括以下数据成员:BS DEGRAME name、BS GPA@derek
public partial class Form2 : Form, IProperties
{
    public Form2()
    {
        InitializeComponent();

    }

    public int PropertyA { get; set; }
    public int PropertyB { get; set; }
}