1

i have a enable and disable function in my program when determined the program is working... i wont the following parameter 'c' to be either Button, Label, or another Object that handles .Enabled

private void getWorkingChanged(Button c)<<--This is where i wont c to be multiple objects
{
    c.Enabled = !c.Enabled;
}

2 Answers 2

9

The base Control object has an Enabled property:

private void getWorkingChanged(Control c) {
    c.Enabled = !c.Enabled;
}
Sign up to request clarification or add additional context in comments.

Comments

1

if you are getting any control then just do

private void getWorkingChanged(Control c)<<--This is where i wont c to be multiple objects
{
    c.Enabled = !c.Enabled;
}

if you want it to be of different object you'll have to create interface

public interface IEnabler
{
    void Enable();
}

and then do

private void getWorkingChanged(object c)<<--This is where i wont c to be multiple objects
{
    IEnabler ie = c as IEnabler;
    if(ie != null)
       ie.Enable();
}

but of course you'll have to implement your own Enable method for what object you want to do enable on your getWorkingChanged method

5 Comments

@DanielJones good to hear(accept simon's answer or mine if you've got your needed answer by clicking the "v" sign)
@DanielJones sry, no :), but you can +1 both of us
Sure, what is +1? sorry I'm kinda not use to this website!
@DanielJones the arrow above the number you see next to each answer
Thanks i have it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.