Visual Studio 2008 does not recognize C# form

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2198 Views - Last Post: 12 June 2011 - 10:54 AM Rate Topic: -----

#1 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 10:58 AM

Hi
I'm having a weird problem with a VS C# project. I know this may sound stupid but this happens to me almost every time I try to import a form.
I am trying to add an existing form from a different project to my current project. I used Add Existing Item option to add the form to my project and it worked fine. I used the refractor to change the namespace and this also worked fine. I can edit the form & write code. However since this is not the main form I need to call it from a parent form and here's the problem: it's as if the form does not exist.
If I try this
frmName frm = new frmName();
frm.ShowDialog(this);


frmName is highlighted in red and I get "Are you missing a using directive or an assembly reference?" error.
Any ideas why is this happening?
Sorry if this isn't clear enough, I don't even know how to explain this.

Is This A Good Question/Topic? 0
  • +

Replies To: Visual Studio 2008 does not recognize C# form

#2 lordofduct  Icon User is offline

  • I'm a cheeseburger
  • member icon


Reputation: 2531
  • View blog
  • Posts: 4,631
  • Joined: 24-September 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:02 AM

are you sure the namespace is updated (in both the designer code and the common code, note that Forms are made of 2 partial classes)?
Was This Post Helpful? 0
  • +
  • -

#3 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:13 AM

Yup. I double checked.
Also, since I usually put all the forms in one folder called Forms I add
using Project_Namespace


so that I can access the folder like this
Forms.frmName frm = new Forms.frmName();
frm.ShowDialog(this);


but this also didn't work.
Don't know if this is the best way to do it but it always worked.
Was This Post Helpful? 0
  • +
  • -

#4 Curtis Rutland  Icon User is offline

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


Reputation: 4437
  • View blog
  • Posts: 7,713
  • Joined: 08-June 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:18 AM

The folder doesn't actually matter. When you create a new item in that folder, by default the folder becomes part of the namespace, but when you move or copy stuff to it, the namespace is whatever it was before it went into the folder.

Go ahead and post the full code for the form, and the file you're trying to use the form in. Use [spoiler][/spoiler] tags if there's a lot of code.
Was This Post Helpful? 0
  • +
  • -

#5 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:29 AM

This is the code for frmMain - all it does is to open 3 external apps.
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 System.Diagnostics;

namespace Salieri_Pizza
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnPizzaOrder_Click(object sender, EventArgs e)
        {
            Process PO = Process.Start("Pizza Order.exe");
        }

        private void btnSSS_Click(object sender, EventArgs e)
        {
            Process SSA = Process.Start("Salieri System Administration.exe");
        }

        private void btnSM_Click(object sender, EventArgs e)
        {
            Process SM = Process.Start("Salieri Manager.exe");
        }

        private void btnAbout_Click(object sender, EventArgs e)
        {
            frmAbout frmAbout = new frmAbout();
            frmAbout.ShowDialog(this);
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}



This is the code for the child form frmAbout, the one I am trying to open:
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 Microsoft.Win32;		// Required for the registry classes.
using System.IO;			// Required for the Path class.
using System.Diagnostics;	// Required for the process classes.
using System.Management;

namespace Salieri_Pizza
{
    public partial class frmAbout : Form
    {        
        public frmAbout()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSysInfo_Click(object sender, EventArgs e)
        {
            SysInfo();
        }

        private void lstProd_SelectedIndexChanged(object sender, EventArgs e)
        {   
            if (lstProd.SelectedIndex == 0)
            {
                ListViewItem lstDet = new ListViewItem();
                lstvwDet.Items.Clear();
                lstvwDet.Items.Add(lstDet);
                lstDet.ImageIndex = 0;
                lstDet.SubItems.Add("Salieri Pizza Order  v1.0.0.0");
                lstvwDet.View = View.Details;
            }

            else if (lstProd.SelectedIndex == 1)
            {
                ListViewItem lstDet = new ListViewItem();
                lstvwDet.Items.Clear();
                lstvwDet.Items.Add(lstDet);
                lstDet.ImageIndex = 1;
                lstDet.SubItems.Add("Salieri Manager v1.0.0.0");
                lstvwDet.View = View.Details;
            }

            else if (lstProd.SelectedIndex == 2)
            {
                ListViewItem lstDet = new ListViewItem();
                lstvwDet.Items.Clear();
                lstvwDet.Items.Add(lstDet);
                lstDet.ImageIndex = 2;
                lstDet.SubItems.Add("Salieri System Administration v2.0.0.0");
                lstvwDet.View = View.Details;
            }
        }

        private void SysInfo()
        {
            string windir = Environment.GetEnvironmentVariable("WINDIR");
            string info = null;

            if (info == null)
            {
                info = Path.Combine(Path.Combine(windir, "sysnative"), "msinfo32.exe");
                if (!File.Exists(info))
                {
                    info = null;
                }
            }
            if (info == null)
            {
                info = Path.Combine(Path.Combine(windir, "system32"), "msinfo32.exe");
                if (!File.Exists(info))
                {
                    info = null;
                }
            }
            if (info == null)
            {
                info = "msinfo32.exe";
            }
            Process.Start(info);
        }
    }
}



I know this is stupid since it's only an About form I can design in 5 minutes but this happened before with other forms than About.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland  Icon User is offline

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


Reputation: 4437
  • View blog
  • Posts: 7,713
  • Joined: 08-June 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:32 AM

Did you also copy the .designer.cs file over with it? There should also be a .resx file. They all go together to make up the form. If any are missing, it could cause problems.
Was This Post Helpful? 0
  • +
  • -

#7 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:35 AM

Yes, all 3 files are there and I can view all of them and also edit the designer.cs. I just didn't post the code for the .designer.cs.
Was This Post Helpful? 0
  • +
  • -

#8 Curtis Rutland  Icon User is offline

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


Reputation: 4437
  • View blog
  • Posts: 7,713
  • Joined: 08-June 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:37 AM

Hmm. Well, I don't know. I'd just create a new form and copy the important code over.
Was This Post Helpful? 0
  • +
  • -

#9 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:40 AM

View PostCurtis Rutland, on 25 May 2011 - 12:37 PM, said:

Hmm. Well, I don't know. I'd just create a new form and copy the important code over.

It's not a big problem since it's only about form but I was quite curios.
Thanks for the help :)
Was This Post Helpful? 0
  • +
  • -

#10 Curtis Rutland  Icon User is offline

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


Reputation: 4437
  • View blog
  • Posts: 7,713
  • Joined: 08-June 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 11:48 AM

Wish I had a better answer for you. Sometimes you just have to be there, in front of it to solve it.
Was This Post Helpful? 0
  • +
  • -

#11 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 12:19 PM

View PostCurtis Rutland, on 25 May 2011 - 12:48 PM, said:

Wish I had a better answer for you. Sometimes you just have to be there, in front of it to solve it.

Yeah, I know. It's no big deal right now :) Thanks
Was This Post Helpful? 0
  • +
  • -

#12 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

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

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 12:54 PM

Close VS and open it again? Seems like a weird issue.
Was This Post Helpful? 0
  • +
  • -

#13 daydr3am3r  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 101
  • Joined: 10-April 09

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 02:01 PM

View Posteclipsed4utoo, on 25 May 2011 - 01:54 PM, said:

Close VS and open it again? Seems like a weird issue.

Done that and it didn't work out.
Was This Post Helpful? 0
  • +
  • -

#14 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5438
  • View blog
  • Posts: 11,668
  • Joined: 02-June 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 04:51 PM

Did you change the namespace in the form.Designer.cs as well?
Otherwise the Designer.cs file is in a different namespace than the form.cs file

Right-click on the project and choose 'Clean project', then build it again.
Was This Post Helpful? 1
  • +
  • -

#15 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Visual Studio 2008 does not recognize C# form

Posted 25 May 2011 - 05:17 PM

I remember when this happened to me before. All I had to do was just rename the namespaces and classes. The only thing I can say is to try and copy the code you need and hopefully you do not need to re-design too much. It happened to me about back in 2010.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2