-3
你可以在下面的圖片中看到,當我把這種窗體稱爲這種窗體時,它會掛起,我不能做任何功能,我可以停止執行。winform c#一個窗體不能正常打開
它以前工作的罰款幾天,現在還不是。我從一個主頁面調用這個表單,並且我有其他表單工作正常,它只是這個表單,我有一個問題,我試圖重做沒有改變事物的表單。
我在這個表格中使用的代碼。
namespace Voice_based_Transport_enquiry_System
{
public partial class air : Form
{
SqlConnection con = new SqlConnection(@"Data Source =.; AttachDbFilename=C:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\Enquiry.mdf;Integrated Security = True; Connect Timeout = 30");
public air()
{
InitializeComponent();
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
con.Open();
String str = "select * from Air where Air_To = '" + comboBox2.Text + "'and Air_From = '" + comboBox1.Text + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr["Distance"].ToString();
textBox2.Text = dr["Arrival"].ToString();
}
con.Close();
}
private void air1_Load(object sender, EventArgs e)
{
FormBorderStyle = FormBorderStyle.FixedDialog;
MaximizeBox = false;
MinimizeBox = false;
StartPosition = FormStartPosition.CenterScreen;
cl();
cm();
}
public void cl()
{
comboBox2.Items.Clear();
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select DISTINCT Air_To from Air";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
comboBox2.Items.Add(dr["Air_To"].ToString());
}
con.Close();
}
public void cm()
{
comboBox1.Items.Clear();
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select DISTINCT Air_From from Air";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
comboBox1.Items.Add(dr["Air_From"].ToString());
}
con.Close();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
構造函數或Load中的任何附加代碼? –
我有這些onload: FormBorderStyle = FormBorderStyle.FixedDialog; MaximizeBox = false; MinimizeBox = false; StartPosition = FormStartPosition.CenterScreen; –
在Form的構造函數中呢? –