Link to home
Start Free TrialLog in
Avatar of Venkatgvi
VenkatgviFlag for India

asked on

C# + is there a single line function which gives the name of a control?

Is there a single line function which gives the name of a control, if it exists in a specific form/handle by passing the control type
Avatar of miketayo
miketayo
Flag of Nigeria image

why do you want a function to give the name of a control.

first the contol is called with the name and if there is you  will need to pass the name of the control into the function

think of that
Avatar of Rahul Goel

private bool IsControlExists(Type type)
{
    foreach (Control item in this.Controls)
    {
        if (item.GetType() == type)
          return true;
    }
    return false;
}

Open in new window

If the control is inside another container (panel, groupbox, etc) then it won't be found...

...you would need a RECURSIVE routine to search the entire Form.
ASKER CERTIFIED SOLUTION
Avatar of Venkatgvi
Venkatgvi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Venkatgvi

ASKER

As Idle mind said, i can recursively loop across all the controls to find the statusbar object, but my current requirement is to use a predefined function or an API to solve the issue.
hi,

i dont think that they is any single line api, if in another control just write a function to loop and get the control out using typeof