Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

how to make a methode accessible from all the forms c#

you can use an interface 
  
  1-Create an interface (Let's call it myInterface)
  2- Add a public static method in myInterface (The method can be return any type or it can be void) 
  //  void Mymethod();
  3- override the method in any forms you want (
      for that 
         you should implement the interface in the form 
                  //  public partial class theForm : Form , myInterface
          Then overrid the method this way 
                  // myInterface.Mymethod(){
                     //do some coding
                  
                  }
   4-And when ever you want to use it call it this way 
    //   myInterface NameIt = (myInterface)Application.OpenForms["theForm"];

      //if (NameIt != null) NameIt.Mymethod();
    
 
PREVIOUS NEXT
Tagged: #methode #accessible #forms
ADD COMMENT
Topic
Name
5+4 =