Dear community,

Isolating the problem, I have 2 forms - frmMain and frmOther. I have a button btnAlarm on frmOther and a label lblWarning on frmMain. When the btnAlarm on frmOther is pressed, the lblWarning on frmMain should change color to red. Is there a way to do this in C#?

Also, is there a way to invoke a method of frmMain from frmOther?

I'm a beginner in C# and tried to look through different forums but could not find the solution.
If anyone knows how to deal with this problem, could you please help me out?
Thank you in advance!

Public property in frmMain get/set the label's background.

frmMain.cs

public Color ChangeColor
        {
            get { return label1.BackColor; }
            set { label1.BackColor = value; }
        }

frmOther.cs - Click handler of button.

private void button1_Click(object sender, EventArgs e)
        {
            foreach (Form frm in Application.OpenForms)
            {
                if (frm is frmMain)
                    (frm as frmMain).ChangeColor = System.Drawing.Color.Red ;

            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.