If a Superclass has a function A() which changes a Label to “Hello World”. How can I get a subclass to call A() with the same result? As of now, I get no compile error, but the text won’t change!
Example code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
FunctionA("Hello");
}
public void FunctionA(string s)
{
label1.Text = s;
}
private void button2_Click(object sender, EventArgs e)
{
Test t = new Test();
}
}
class Test : Form1
{
public Test()
{
FunctionA("World");
}
}
Both the
Formsmust be having their ownLabelcontrol to display messages. You might be using oneLabelto show the message which is not part of displayingForm.I am not sure what are to trying to achieve but why don’t you just pass the
Labelcontrol to FunctionA to modify the message this way:ADDED: You can do it this way:
First creating the instance of
FormA.Passing the instance of
FormAtoFormBby exposing a parameterized constructor for any manipulation inFormAfrom withinFormB.