pulling forms out of applications.

Is there a way to pull out what forms are in a particular application that get's passed in Also does any one know how to find out the name of the exe file that call's the dll Anything would be very helpful.

Thanks,

Matt



Answer this question

pulling forms out of applications.

  • Andrew Oliver

    mattdawg wrote:
    I am sorry that was my own stupid mistake. I meant I want to use reflection to find out the forms in an application. Now I am just wondering is it possible to do so without passing any thing into the function And if it is possible how
    If you just want the running executable's Forms then Assembly.GetExecutingAssembly().GetTypes() and Type.BaseType will do the trick.

  • zcz

    Also a little off the subject is there a way to see if a control has an event handler for a particular event like a "click" event
  • Jiffy

    I'm not sure the context in which your HookEvents is called, so I'm not sure what Form you're talking about.

    If you just want the "active" form for the application you can iterate the Application.OpenForms property:


    foreach(Form form in Application.OpenForms)
    {
    if(form.Active)
    {
    activeForm = form;
    break;
    }
    }



  • Terry Nguyen

    Hey matt nice name. I actually just opened up a new post asking the same thing. Great minds think alike. I also need to know how to tell when a form get's opened. Does anybody know how to do this
  • rradtke

    I have a function that saves all of the EventHandlers and the time they were called. So I need to call this right went the forms open. The Application.OpenForms would work if I new how to call it when the application opened a new form. Do you know how to do that I am sorry if my questions are confusing. I am still trying to figure out how to approach this problem my self so I am not doing a good job of asking the right question. One question is there a way to see all of the forms an application is going to use before they are used
  • WeldFire

    In terms of Form-based classes contained in an assembly, you could use reflection to enumerate all the types in an assembly (see Assembly.GetTypes) and see if any derive from Form (see Type.BaseType).

    You can get the main assembly via Assembly.GetExecutingAssembly(). If you have an object, and you want to know what assembly is is from you can use Object.GetType() to get it's type, then use the Type.Assembly property.



  • Sanket Shah

    I guess I just don't understand how to access the form after you use Type.BaseType. Here is what I am trying to get it to work with. How do I pass the form into this function

    private void HookEvents(Control ctl)

    {

    Type t = ctl.GetType();

    EventInfo[] events = t.GetEvents();

    foreach (EventInfo evt in events)

    {

    if (evt.Name == "Click")

    {

    mActions.Add(new Action(ctl, evt, mSequence));

    }

    }

    foreach (Control c in ctl.Controls)

    {

    HookEvents(c);

    }

    }


  • Itsme850

    mattdawg wrote:
    Ok I got the calling assembly thing figured out thanks a lot. Now how do I reflection to find out the forms in a particular form without passing it in If you have to pass it in that's fine. Also is there a way to grab forms when they get created
    I'm not clear one what you mean by "found out the forms in a particular form". If you have a form object of some sort and you want to find any other forms in the same assembly, you can use the GetType().Assembly on that form object to find out what assembly hosts that Form-based class. From there you can use GetTypes() to enumerate all the types in that assembly looking for a type whose BaseType is Form.

  • Carlos90210

    I am sorry that was my own stupid mistake. I meant I want to use reflection to find out the forms in an application. Now I am just wondering is it possible to do so without passing any thing into the function And if it is possible how
  • Labm1ce

    Ok I got the calling assembly thing figured out thanks a lot. Now how do I reflection to find out the forms in a particular form without passing it in If you have to pass it in that's fine. Also is there a way to grab forms when they get created
  • pulling forms out of applications.