0

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!

Edited by Ironheart: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
1

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 ;

            }
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.