2012-09-17 40 views
0

我有这个奇怪的错误/冲突。我的申请有两种形式。两者都有相同的名称空间,当我尝试创建下一个表单的对象时,它不会显示出来。这是我在Form1中C#表单不包括在项目中

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; 
     } 
    } 
+0

显示您的解决方案资源管理器。 –

+1

是不是Form2类缺失? 。有名称为Form2.cs的类文件,但请参见类本身 – levi

+0

也查看form2的属性,并确保将生成操作设置为编译。 –

回答

1

您没有Form2分类。你有一个MR6651_DEMO类。尝试创建一个实例。你的编译器应该告诉你到底发生了什么错误。

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

+0

谢谢一吨Steen。问题解决了 :) – saadasharif

1

表单中的2码有一个名为Form2的无级类定义。我想这就是为什么找不到的原因。

+0

谢谢乔,问题解决了:) – saadasharif