4
To understand what I want to do, note the Formclosing() parameter of Windowsforms:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
var r = e.CloseReason;
}
By analyzing this method, I cannot modify the Closereason property within the method, just receive. But how is this property populated by values, and its access is GET? How does this method work internally?
I am trying to copy the same reasoning of the above method, but I am not getting it. The way I am doing below, is giving error.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Modify modify = new Modify();
modify.Refresh += Modify_Refresh;
modify.Start();
}
// esse é o método que está seguindo a mesma linha de raciocínio do método acima
private void Modify_Refresh(ValueArgs e)
{
var r = e.IsRunning;
}
}
public class Modify
{
public delegate void EventRefresh(ValueArgs e);
public event EventRefresh Refresh;
public void Start()
{
ValueArgs valueArgs = new ValueArgs();
valueArgs.IsRunning = true;
Refresh(valueArgs);
}
}
public class ValueArgs
{
public bool IsRunning { get; }
}
Note that when I set Isrunning to TRUE, it gives error saying that the property is not assignable, but read-only. How do I make this code work the right way, following the same line of reasoning as the Formclosing() method of Windows Form?