c# - Change ToolStripButtomItem Attributes Using EventHandler -


this first question on stackoverflow, therefore errors in asking-style aren't on purpose.

i'm both, new c# concept of event-handling, know, if there possibility have value of toolstripbuttonitem-attribute changed eventhandler.

the context following:

the code starts initializing ui contains windows.forms- elements. toolstripbuttomitem of interest me, has it's enabled-attribute set false default-value. functionality of button switch comparision-view reference file exists. allready can case when programm-start, otherwise reference file might created during runtime. of course, perform

button.enabled=system.io.file.exists(reference-file)  

with initilization ,

createfile(referencefile){     ...     button.enabled = true; } 

but seems rather crude me.

instead 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 intend is, have button enabled reference-file existst. there multiple ways create reference-file, , there goint more in future. avoid setting enable-value in each of createreferencefile()-methods, concept of eventhandling seems quite deal me.

the program i'm trying run quite comprehensive, "polling" no option @ place.

i suggest use filesystemwatcher , set enabled property every time goes of.

    private void startlistening(string path)     {         var watch = new filesystemwatcher();         watch.path = path;         watch.filter = "*.*";         watch.created += updatestate;         watch.deleted += updatestate;     }      void updatestate(object sender, filesystemeventargs e)     {         mybutton.enabled = file.exists(@"c:\folder\file.txt");     } 

ps: basic example code, need make sure have reference mybutton , have correct path there ...


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -