locked
How i can call other project form ? RRS feed

  • Question

  • Hi All,

    may i know how i can call other projects form ?

    Thanks,
    Jeff.
    MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
    Thursday, March 12, 2009 2:33 AM

Answers

  • Right-click on the references folder in the solution explorer, and choose add reference. 

    Select the browse tab. Browse to the project folder of the project you want to use. Go to the debug folder and select the .exe of the project.

    Now open the referemces folder. You should see the name of your project in that folder. 

    Go to the "using" directives and add "using" and then the name of the projects .exe.

    Go the click event, or whatever you are using to call the form, and then create a new instance of the form.

    For example. Say you have a project called MyProject. In that project you have a form called MyForm. After adding a reference to MyProject, you should see "MyProject" in the reference folder. 

    The namespace would be: 

    using MyProject; 

    The code would be:

    private void btnOpenForm_Click(object sender, EventArgs e)  
    {  
        MyForm myForm = new MyForm();  
        myForm.Show();  

    When the button is clicked, the form from MyProject will run.

    Please post back if this didn't work for you, or if my explanation wasn't clear.

    • Proposed as answer by lesPaul456 Thursday, March 12, 2009 2:50 AM
    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:37 AM
    Thursday, March 12, 2009 2:50 AM
  • You can reference a class library. Just select the .dll instead of a .exe. The code should be the same.

    Try it out and if you can't get it to work please let me know.

    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:37 AM
    Thursday, March 12, 2009 2:57 AM
  • Hi LesPaul,

    Its fine now. I can call the form now. Thanks, Jeff. At first attempt its failed due to i add windows form from solutions. hehe.so embrassing.
    MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:36 AM
    Thursday, March 12, 2009 3:23 AM

All replies

  • Right-click on the references folder in the solution explorer, and choose add reference. 

    Select the browse tab. Browse to the project folder of the project you want to use. Go to the debug folder and select the .exe of the project.

    Now open the referemces folder. You should see the name of your project in that folder. 

    Go to the "using" directives and add "using" and then the name of the projects .exe.

    Go the click event, or whatever you are using to call the form, and then create a new instance of the form.

    For example. Say you have a project called MyProject. In that project you have a form called MyForm. After adding a reference to MyProject, you should see "MyProject" in the reference folder. 

    The namespace would be: 

    using MyProject; 

    The code would be:

    private void btnOpenForm_Click(object sender, EventArgs e)  
    {  
        MyForm myForm = new MyForm();  
        myForm.Show();  

    When the button is clicked, the form from MyProject will run.

    Please post back if this didn't work for you, or if my explanation wasn't clear.

    • Proposed as answer by lesPaul456 Thursday, March 12, 2009 2:50 AM
    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:37 AM
    Thursday, March 12, 2009 2:50 AM
  • Hi Lespaul,

    but my other project do not have exe. its a class library.

    Please advice.

    Thanks,
    Jeff.
    MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
    Thursday, March 12, 2009 2:54 AM
  • You can reference a class library. Just select the .dll instead of a .exe. The code should be the same.

    Try it out and if you can't get it to work please let me know.

    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:37 AM
    Thursday, March 12, 2009 2:57 AM
  • Hi LesPaul,

    I tried to add class library from project1 name ubsaccconnector.

    now i had tried to create 1 dummy form to call project2 form.

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    //using System.Linq;

    using System.Text;

    using System.Windows.Forms;

    using UbsaccConnector;

    namespace test_act

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    }

    private void button1_Click(object sender, EventArgs e)

    {

    UbsaccConnector.ModifyConnectionForm myForm = new UbsaccConnector.ModifyConnectionForm();

    UbsaccConnector.ModifyConnectionForm.Show();

    }

    }

    }

    but it seems had errors. 

    Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Forms.Control.Show()' C:\Users\Jeff Ng\Documents\Visual Studio 2008\Projects\test-act\test-act\Form1.cs 29 13 test-act


    Thanks,
    Jeff.


    MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
    Thursday, March 12, 2009 3:07 AM
  • Hi LesPaul,

    Its fine now. I can call the form now. Thanks, Jeff. At first attempt its failed due to i add windows form from solutions. hehe.so embrassing.
    MCP - SQL SERVER 2k/ WINDOWS XP , VFP 6 YEARS
    • Marked as answer by Harry Zhu Monday, March 16, 2009 9:36 AM
    Thursday, March 12, 2009 3:23 AM
  • Hey Jeff, 

    You're welcome. I'm really glad you got it to work.

    Thursday, March 12, 2009 1:25 PM