我遇到了这个奇怪的错误/冲突。我的申请中有两个表格。两者都有相同的命名空间,当我尝试创建下一个形式的对象时,它不会出现。这是我在 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;
}
}