none
Alternative way for using forms from ProjectA in ProjectB other than referencing method

    Question

  • Hi All,

    I have a scenario where in need to make use of the vb.net forms in ProjectA by other projects. All these projects are under single solution.

    I know to achieve this by adding reference to ProjectA in other projects. Want to know if there are any other way to achieve this.

    I basically want to eliminate the dependency on this DLL. 

    Thanks in advance for your assistance. 


    • Edited by SaSat Thursday, March 30, 2017 4:12 AM
    Thursday, March 30, 2017 4:10 AM

Answers

  • One idea is to have one windows form project with all the forms you want to share in other projects. To share a form from this project, in the main project select add an existing item, traverse to the shared project and select the form as shown below.

    In the solution explorer you will see that form with a special icon e.g.

    Any changes made (in this case) to EditForm in either project are changing that form. Last thing, for the SharedForms project we don't want someone running it so let's fix that.

    In the shared form project, select project properties, press "View Application Events" button on the Application tab.

    A code window opens, select from the top middle combo box (MyApplication Events), on the right combo box select Startup. An event is created, add e.Cancel = true (see below). Now if someone tried to run that executable it will not start.

    Imports Microsoft.VisualBasic.ApplicationServices
    
    Namespace My
        ' The following events are available for MyApplication:
        ' Startup: Raised when the application starts, before the startup form is created.
        ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
        ' UnhandledException: Raised if the application encounters an unhandled exception.
        ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
        ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
        Partial Friend Class MyApplication
            Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
                e.Cancel = True
            End Sub
        End Class
    End Namespace
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by SaSat Friday, March 31, 2017 6:41 AM
    Thursday, March 30, 2017 10:05 AM
    Moderator

All replies

  • I know to achieve this by adding reference to ProjectA in other projects. Want to know if there are any other way to achieve this.

    You can copy the forms from project A to project B. 

    The point of using a DLL is that the whatever projects use these forms, they are all using the same DLL - there is a single source for that code. If you don't use the DLL you lose the advantage of having a single source, and each form has to be maintained and updated within the projects you copied it into.

    Thursday, March 30, 2017 4:49 AM
  • Create a Class Library instead of Project A

    Success
    Cor

    Thursday, March 30, 2017 5:41 AM
  • if we create Class library which will generate DLL should be referred in ProjectB. Again we are in same problem.
    Thursday, March 30, 2017 6:06 AM
  • I dont want to maintain duplicate of the forms in two different Project.

    Is there any other way?

    Thursday, March 30, 2017 6:07 AM
  • You can place the same files in different folders using Operating System features, such as “hard links”. The known command-line tools are “mklink” and “fsutil”. An example:

      mklink /h "C:\ProjectB\Form2.vb" "C:\ProjectA\Form2.vb"

    Then Form2.vb will appear in ProjectB folder becoming a common file. Operation has to be repeated for “.Designer.vb” and “.resx” files.

    Then click “Show All Files” in Solution Explorer for ProjectB, right-click Form2, then “Include in Project”.

    Though this requires attention in case of copying and deleting files. Seems that Class Libraries are more suitable.

    Visual Studio also includes a special kind of projects — “Shared Projects” — which are good for other types of common files.


    • Edited by Viorel_MVP Thursday, March 30, 2017 8:49 AM
    Thursday, March 30, 2017 8:47 AM
  • One idea is to have one windows form project with all the forms you want to share in other projects. To share a form from this project, in the main project select add an existing item, traverse to the shared project and select the form as shown below.

    In the solution explorer you will see that form with a special icon e.g.

    Any changes made (in this case) to EditForm in either project are changing that form. Last thing, for the SharedForms project we don't want someone running it so let's fix that.

    In the shared form project, select project properties, press "View Application Events" button on the Application tab.

    A code window opens, select from the top middle combo box (MyApplication Events), on the right combo box select Startup. An event is created, add e.Cancel = true (see below). Now if someone tried to run that executable it will not start.

    Imports Microsoft.VisualBasic.ApplicationServices
    
    Namespace My
        ' The following events are available for MyApplication:
        ' Startup: Raised when the application starts, before the startup form is created.
        ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
        ' UnhandledException: Raised if the application encounters an unhandled exception.
        ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
        ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
        Partial Friend Class MyApplication
            Private Sub MyApplication_Startup(sender As Object, e As StartupEventArgs) Handles Me.Startup
                e.Cancel = True
            End Sub
        End Class
    End Namespace
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by SaSat Friday, March 31, 2017 6:41 AM
    Thursday, March 30, 2017 10:05 AM
    Moderator
  • Yea but in your way it would be simple to embed for instance MS Word inside another program. 

    That was already tried in 1980 with Visicalc, I can assure you that not any professional company gives you the tools to do that again.


    Success
    Cor

    Thursday, March 30, 2017 10:22 AM