简体   繁体   中英

C# Form not included in the project

I am having this strange error/conflict. I have two forms in my application. Both have same namespaces, and when I try to create an object of the next form it doesn't shows up. This is my code in Form1

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

And when I add another form in the project (like form3.cs) it shows up. Why is this "form2" missing? Although it is available in the project.

Form 1 code

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 code

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

In your Form 2 Code there is no Class Definition for a Class named Form2. I guess thats the cause why it can't be found.

You have no Form2 class. You've got a MR6651_DEMO class. Try creating an instance of that instead. Your compiler should be telling you exactly what's wrong.

The name of a file doesn't have to have anything to do with the class contained within - that they often match is a matter of hygiene and sanity. =)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM