Hi
I need change variables in form from class
I have event on button.
private void listenClick(object sender, EventArgs e)
{
if (button == false)
{
button = true;
listen.Text = "Close";
listen.BackColor = Color.Red;
textLp.Enabled = false;
textRp.Enabled = false;
textIp.Enabled = false;
textSend.Enabled = true;
}
else
{
button = false;
listen.Text = "Listen";
listen.BackColor = Color.Lime;
textLp.Enabled = true;
textRp.Enabled = true;
textIp.Enabled = true;
textSend.Enabled = false;
}
}
I need change all this variables in class.
Loading
VulpesPosted Aug 20, 2013, 8:19 AM
f1.listen.BackColor = Color.Blue; // or whatever
PavolPosted Aug 20, 2013, 8:10 AM
VulpesPosted Aug 20, 2013, 7:25 AM
The bool 'button' variable does not need to be changed.
PavolPosted Aug 20, 2013, 7:10 AM
VulpesPosted Aug 18, 2013, 2:06 PM
PavolPosted Aug 18, 2013, 4:57 AM
VulpesPosted Aug 16, 2013, 5:36 AM
In the Properties Box, change the Modifiers property of the controls you want to access from private to internal.
In your class, get a reference to the Form (say Form1) which contains those controls as follows:
Form1 f1 = Application.OpenForms["Form1"] as Form1;
You can now access the controls like this:
if (f1 != null)
{
f1.listen.Text = "Close";
f1.textRp.Enabled = false;
// etc.
}
If listenClick is an event handler in Form1, you can also fire it from the class without actually clicking the button as follows:
f1.listen.PerformClick();
You'll need to make sure that your class file has the following 'using' directive as it may not be added by default:
using System.Windows.Forms;
Iftikar HussainPosted Aug 16, 2013, 5:14 AM
Not clear about your query. Can you bit explain more?
Regards,
Iftikar