Passing a button object to a function

Hi everyone,

I may be a little verbose on my problem here simply because I do not know where to begin to solve it.

My application has two forms and a separate file for custom functions:

frmPreferences.cs has a label and a button:

When frmPreferences originally loads, btnAccept.enabled = false

If lblIndexFileLocation.text changes, I want btnAccept.enabled = true

So i want to have a function in myFunctions.cs that will accept a button object as an argument, take this object, and changed it's enabled property to true.

My questions are:
How do I write the function itself to accept the button object as an argument?

How do i write the call to that function correctly?

This seems like there should be a simple solution, but after spending an hour on google, I just get the feeling i don't even know how to ask the question correctly.


  • Hi,

    myFuncions.cs will need to have a using directive like:

    using System.Windows.Forms;

    To be able to see the Button class. Then you just write it as a normal parameter:

    public static void TheFunction(Button B)
    B.Enabled = true;

    Calling it is just passing the button as a parameter to the function, just as you'd pass a parameter in any other call.


    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion