Working with multiple c# forms... wanting to open existing form with b

Working with multiple c# forms... "type or namespace cannot be fou

  • (2 Pages)
  • +
  • 1
  • 2

16 Replies - 10271 Views - Last Post: 09 September 2010 - 07:25 AM Rate Topic: -----

#1 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 08:59 AM

Hello,
I am kind of new to C#... using Visual Studio, creating a large project with multiple forms. Having an issue with wanting to open an existing form when clicking a button.
I have the following code...

private void newButton_Click(object sender, EventArgs e)
{
myNewForm.Show();
}

But keep getting one error:

"The type or namespace name "...." cannot be found (are you missing a using directive or an assembly reference?" The other form is added to the project, I am just confused as to what exactly I need to reference. Probably a silly error, but it is driving me crazy! Any help is appreciated - Thanks! :dontgetit:

Is This A Good Question/Topic? 0
  • +

Replies To: Working with multiple c# forms... wanting to open existing form with b

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:02 AM

Is there a reason you failed to post the most important part of the exception? It would be helpful if you told us the type or namespace name about which it's complaining!
Was This Post Helpful? 1
  • +
  • -

#3 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:16 AM

View PostJackOfAllTrades, on 25 August 2010 - 08:02 AM, said:

Is there a reason you failed to post the most important part of the exception? It would be helpful if you told us the type or namespace name about which it's complaining!


Apologies....

"The type or namespace name "myNewForm" cannot be found (are you missing a using directive or an assembly reference?"

(myNewForm is the name of the form it is needing to open)
Was This Post Helpful? 0
  • +
  • -

#4 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1355
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:19 AM

A namespace is used to identify all objects inside a project. Multiple projects can exist in each solution, so having these namespaces helps to identify which project any particular file belongs to. The only thing I can say to help with your issue is to make sure that the namespace on the form you want to open is the same as the namespace that the piece of code you've posted belongs to, or to use a using directive for the proper namespace of the other project at the top of the code file that your posted code comes from. Hopefully this makes sense to you.
Was This Post Helpful? 1
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:30 AM

You need an object named myNewForm in order to be able to call the Show() method on it. You're going to need to show more code I think, if that doesn't make sense to you.
Was This Post Helpful? 1
  • +
  • -

#6 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:36 AM

View PostJackOfAllTrades, on 25 August 2010 - 08:30 AM, said:

You need an object named myNewForm in order to be able to call the Show() method on it. You're going to need to show more code I think, if that doesn't make sense to you.


Yeah, still pretty confused... Thanks for your help - here is my full code:

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;


namespace AssignItemWorksheet
{
    public partial class frmAssignItemWorksheet : Form
    {
        public frmAssignItemWorksheet()
        {
            InitializeComponent();
        }
private void newButton_Click(object sender, EventArgs e)
      {
            myNewForm.Show();
       }
}
}

This post has been edited by JackOfAllTrades: 25 August 2010 - 09:47 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0
  • +
  • -

#7 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1355
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:37 AM

Yea, as Jack already mentioned, you're definitely going to have to have a form already added to the project that has the name "myNewForm".

After looking over your code, I don't think it's a problem with a namespace, but rather that you're trying to use the Show() method on a "type" that doesn't exist. If this form does exist, then make sure the namespace on it is correct.

This post has been edited by Kilorn: 25 August 2010 - 09:40 AM

Was This Post Helpful? 2
  • +
  • -

#8 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:39 AM

That's all the code you have?
Was This Post Helpful? 0
  • +
  • -

#9 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:43 AM

View Posteclipsed4utoo, on 25 August 2010 - 08:39 AM, said:

That's all the code you have?


Yes, so far this is all the code I have so far - the Form is completely done as far as Design... I am now trying to do simple things such as linking buttons at this point.
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5960
  • View blog
  • Posts: 23,238
  • Joined: 23-August 08

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:47 AM

Please, when you're posting code, do so in code tags.

:code:
Was This Post Helpful? 1
  • +
  • -

#11 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,480
  • Joined: 08-June 10

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 09:48 AM

The simple reason is because you haven't declared myNewForm at all. If it is a new form you want to show, you'll have to do something like:

//replace "MyNewForm" with the class name of the form
MyNewForm myNewForm = new MyNewForm();
myNewForm.Show();


If it's a form that already exists, you'll need to get a reference to it to be able to do anything with it.
Was This Post Helpful? 1
  • +
  • -

#12 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 11:05 AM

Thank you very much for your help! However, it is opening a form now, but it is the wrong one (it is the form that is already displayed - frmAssignItemWorksheet whereas it should be myNewForm)


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;


namespace AssignItemWorksheet
{
    public partial class frmAssignItemWorksheet : Form
    {
        public frmAssignItemWorksheet()
        {
            InitializeComponent();
        }

        public partial class frmNewReleaseOrderWorksheet : Form
        {

            private void newButton_Click(object sender, EventArgs e)
            {
frmAssignItemWorksheet myNewForm = new frmAssignItemWorksheet();
myNewForm.Show();

            }
        }
    }
}


Was This Post Helpful? 0
  • +
  • -

#13 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1355
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 11:08 AM

That is because of the following line:
frmAssignItemWorksheet myNewForm = new frmAssignItemWorksheet();


You currently have the variable "myNewForm" set to type "frmAssignItemWorksheet", therefore when you call the Show() method for the instance "myNewForm", all you're doing is opening a new instance of "frmAssignItemWorksheet".

If you want a seperate form by the name of myNewForm, then you'll have to add a second form to your project and use it instead of the "frmAssignItemWorksheet".
Was This Post Helpful? 1
  • +
  • -

#14 mjw85  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 01-October 07

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 11:43 AM

I now have a new error that is preventing me from moving any farther - when I go to run the project I get the error "System.ComponentModel.ComponentResourceManagerresources=newSystem.ComponentModel.ComponentResourceManager(typeof(myNewForm));" in the designer file

The project will run, but no longer opens up a form period. :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#15 Kilorn  Icon User is offline

  • XNArchitect
  • member icon



Reputation: 1355
  • View blog
  • Posts: 3,528
  • Joined: 03-May 10

Re: Working with multiple c# forms... wanting to open existing form with b

Posted 25 August 2010 - 11:47 AM

Can you paste the code that the error is coming from on here and let me take a look. I'm not sure I understand the error.
Was This Post Helpful? 1
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2