How to use a global function

We are currently developing a website. Is there a way to globally use a function without declaring it in all forms (declare only on parent form or main page)

1 answer

  • answered 2018-05-16 06:25 T.S.

    You don't really want to declare globally used function on any form. You can create a static class

    public static class ClassA
    {
        public static bool MyFunc()
        {
            return true;
        }
    }
    

    This way in the form you will do

    var b = ClassA.MyFunc();
    

    Or, another way. Create your base form and derive your forms from it

    public class MyFormBase : Page
    {
        protected bool MyFunc()
        {
            return true;
        }
    }
    
    public class MyForm1 : MyFormBase
    {
        private void control_click(sender s, eventargs e)
        {
            var b = MyFunc();
        }
    }