C#表格未包含在项目中

时间:2012-09-17 08:19:10

标签: c# visual-studio-2008

我遇到了这个奇怪的错误/冲突。我的申请表中有两种表格。两者都有相同的命名空间,当我尝试创建下一个表单的对象时,它不显示。这是我在Form1中的代码

Form2 form2 = new Form2();
form2.Show();
this.Hide();

当我在项目中添加另一个表单(如form3.cs)时,它会显示出来。为什么这个“form2”丢失了?虽然它在项目中可用。

表格1代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlServerCe;
using UHF_Demo;

namespace UHF_Demo
 {
   public partial class Form1 : Form
    {
      public Form1()
      {
        InitializeComponent();
    }

    private void submit_Click(object sender, EventArgs e)
    {
         {

        string query = "Select * from login_info where username = '" + username_tb.Text + "' and password = '" + password_tb.Text + "'";

        SqlCeConnection conn = new SqlCeConnection();

        conn.ConnectionString = @"Data Source =\Program Files\valcan\employeedb.sdf";

        SqlCeCommand cmd = new SqlCeCommand(query, conn);

        conn.Open();

        SqlCeDataReader dr = cmd.ExecuteReader();

        int counter = 0;

        while (dr.Read())
        {
            counter = counter + 1;

        }
        if (counter > 0)
        {
         Form2 form2 = new Form2();
            form2.Show();
            this.Hide();
        }
        else
        {
            MessageBox.Show("Invalid Login name or Password. Please try again ....");
        }

        conn.Close();
        dr.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        // TODO: This line of code loads data into the 'locationds.login_info' table. You can move, or remove it, as needed.
        this.login_infoTableAdapter.Fill(this.locationds.login_info);

       }
      }
     }
    }}

Form2代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;
using System.Globalization;
using System.IO;

namespace UHF_Demo
{

public partial class MR6651_DEMO : Form
{
    public bool BeingId = false;

    byte[,] TagBuf = new byte[100, 14];
    byte TagCnt = 0;
    ComPort Port0 = new ComPort();
    private CultureInfo culinfo = CultureInfo.CurrentCulture;
    public MR6651_DEMO()
    {
        InitializeComponent();
        double CostomiseFQ = 900.000;
        for (int i = 0; i < 60; i++)
        {
            comboBox1.Items.Add(CostomiseFQ.ToString("#0.000")+"M");
            comboBox2.Items.Add(CostomiseFQ.ToString("#0.000") + "M");
            CostomiseFQ +=0.5;
        }
        MEMBANK.SelectedIndex = 1;
        WORDPTR.SelectedIndex = 0;
        WORDCNT.SelectedIndex = 0;
        cmbFreqType.SelectedIndex = 2;
        VALUE.Text = "";
        //tabPage3.Parent = null;
        if (culinfo.ToString() == "zh-CN")
        {
            this.Text = "UHF¶ÁдÑÝʾ";
            TabPage page1 = tabControl1.TabPages[0];
            page1.Text = "»¶Ó­";
            TabPage page2 = tabControl1.TabPages[1];
            page2.Text = "EPC²âÊÔ";
            //TabPage page3 = tabControl1.TabPages[2];
            //page3.Text = "6B²âÊÔ";
            label5.Text = "¹¦ÂÊ";
            label8.Text = "ƵÂÊ";
            labStatusBar.Text = "×¼±¸¾ÍÐ÷";
            btnQueryPower.Text = "²éѯ";
            btnSetPower.Text = "ÉèÖÃ";
            EXIT.Text = "Í˳ö";
            chkAutoClr.Text = "¹ýÂËÖظ´±êÇ©";
            ID.Text = "ʶ±ð";
            btnEPClist.Text = "Áбí";
            button1.Text = "EPC¿é²Ù×÷";
            CLEAR.Text = "Çå¿Õ";
            label2.Text = "×ÖµØÖ·";
            label3.Text = "×Ö³¤¶È";
            label4.Text = "Êý¾Ý";
            READ.Text = "¶ÁÈ¡";
            WRITE.Text = "дÈë";
            INIT.Text = "³õʼ»¯";
            label10.Text = "×Ö½ÚµØÖ·";
            label7.Text = "×Ö½Ú³¤¶È";
            label9.Text = "Êý¾Ý";
            btn6BID.Text = "ʶ±ð";
            btn6BRead.Text = "¶ÁÈ¡";
            btn6BWrite.Text = "дÈë";
            btn6BLock.Text = "Ëø¶¨";
            chkClear6B.Text = "¹ýÂËÖظ´±êÇ©";
            btn6BClear.Text = "Çå¿Õ";
            btnSaveFile.Text = "±£´æÎļþ";
            label1.Text = "Êý¾Ý¿é";
            cmbFreqType.Items.Clear();
            cmbFreqType.Items.Add("Öйú");
            cmbFreqType.Items.Add("±±ÃÀ");
            cmbFreqType.Items.Add("Å·ÖÞ");
            cmbFreqType.Items.Add("×Ô¶¨Òå");
            cmbFreqType.SelectedIndex = 2;
            listViewEPC.Columns[0].Text = "EPCÂë";
            listViewEPC.Columns[1].Text = "񅧏";
            label11.Text = "ÆðʼƵµã";
            label12.Text = "ÖÕֹƵµã";
            btn_locktid.Text = "ËøTID";
            btn_seelocktid.Text = "²é¿´TIDËø";
        }
    }
    private void EPC_DEMO_Load(object sender, EventArgs e)
    {
        if (Port0.Open() == 0)
        {
            if (culinfo.ToString() == "zh-CN")
            {
                labStatusBar.Text = "ͨѶ¶Ë¿Ú´ò¿ª³É¹¦!";
            }
            else
            {
                labStatusBar.Text = "Start conmunicate commport success!";
            }
            //aStatus = Port0.SetRf(10, 2);
            Thread.Sleep(500);
            btnQueryPower_Click(sender, e);
            Sound.PlayWAV(@"\Application Data\Rfid\wav\shutter.wav");
            for (int i = 0; i < 223; i++)
                ADDR6B.Items.Add(i.ToString());
            ADDR6B.SelectedIndex = 0;
            ByteCnt6B.SelectedIndex = 0;
        }
    }

2 个答案:

答案 0 :(得分:1)

在您的表单2代码中,没有名为Form2的类的类定义。我猜这就是为什么找不到它的原因。

答案 1 :(得分:1)

你没有Form2课程。你有一个MR6651_DEMO课程。尝试创建一个实例。你的编译器应该告诉你到底出了什么问题。

文件的名称不必与其中包含的类有任何关系 - 它们经常匹配是一个卫生和理智的问题。 =)