2012-09-17 51 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