Results 1 to 8 of 8

Thread: Howto call a form from a comclass

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    29

    Howto call a form from a comclass

    Hi,

    I would like to develop a com-class which shows up a form, (e.g. an easy About-box, just to be very plain), and give the focus to that form. Now I have a project with a com-class and a about-class.

    Somehow I cant show the about-form and give the focus to the form.

    If someone could help me with an example I would be very pleased!

    Roger

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Howto call a form from a comclass

    can you explain what you mean by "com-class"

    To me that sounds like a class dll written in a legacy language like VB6?

    or do you mean something different?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    29

    Re: Howto call a form from a comclass

    I'm trying to understand VS2005

    I've created a new project (ClassLibrary, so I can distribute the DLL) and added a COM-class (Project -> Add Class -> ComClass), so I could expose my code to other programming languages using ActiveX. By using a Sub in the COM-class I want to display a form with e.g. some buttons or just an ordinary about-box. Creating the com-class and access it from the outer world isn't the problem and is already working to call a function and return some values. However the problem is to show up the form and give the form the focus, so I could call a sub from the external application using active-x and do some stuff in VS2005 and than return to the external application.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Howto call a form from a comclass

    You would need to define this form class in the same assembly, or a referenced assembly, and then instantiate it from the COM class. This class may be visible to COM but it is still part of a .NET assembly so it is subject to the same rules and restrictions as any other .NET class. This is how you would do it in a fully .NET environment so it is still the way you must do it a mixed environment.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    29

    Re: Howto call a form from a comclass

    And how could I instantiate the form?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Howto call a form from a comclass

    The same way you create an instance of any form. I'm quite sure you've created forms before.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Howto call a form from a comclass

    E.g.
    VB Code:
    1. Dim myForm As New MyFormClass
    2.  
    3. myForm.Show()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Nov 2005
    Posts
    29

    Re: Howto call a form from a comclass

    I haven't got the show in the functionlist of form1, only:

    .ActiveForm
    .CheckForIllegalCrossThreadCalls
    .DefaultBackColour
    .DefaultForeColour
    .DefaultFont

    and some other... not the normal .show etc...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width