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

Venkatgvi
Venkatgvi used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
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
Rahul Goel ITILSenior Consultant - Deloitte

Commented:

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

Open in new window

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
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.
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Hi,
The Problem is i need to find the handle of Statusbar object in a given Form Handle, so i dont know what is the name of the Statusbar object in the specified form as i can pass any forms handle to the function.

there s an API named getdlgitem, which i hope with solve the purpose, but i am not able to find the Control identifier argument to be passed.

Author

Commented:
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.

Commented:
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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial