this is my first question on stackoverflow, therefore errors in asking-style aren't on purpose.
I'm both, new to C# as to the concept of event-handling, so I would like to know, if there is any possibility to have the value of an ToolStripButtonItem-attribute changed by an EventHandler.
The context is the following:
The code starts by initializing the UI which contains some Windows.Forms- Elements.
The ToolStripButtomItem
that is of interest for me, has it's Enabled-attribute
set to false as default-value. The functionality of this button is to switch into a comparision-view as soon as a certain reference file exists.
This allready can be the case when the programm-start, otherwise the reference file might be created during runtime.
Of course, you could perform
Button.Enabled=System.IO.File.Exists(Reference-File)
with the initilization and than do something like
CreateFile(ReferenceFile){
...
Button.Enabled = true;
}
but this seems rather crude to me.
Instead I would like to something like:
Button.Enabled = new System.EventHandler(this.EnableButton);
with
private void EnableButton(Object sender, EventArgs e){
if(System.IO.FileExists(ReferenceFile)
Button.Enabled = true;
}
What I intend is, to have the button get enabled as soon as the reference-file existst. There are multiple ways to create the reference-file, and there are goint to be even more in the future. To avoid setting the enable-value in each of those createReferenceFile()
-Methods, the concept of EventHandling seems quite like the deal to me.
The program I'm trying to run is quite comprehensive, so "polling" is no option at this place.