2016-09-30 35 views
0

你好我正在使用這個library使用metroframework用戶界面,但我不能關閉winform This.Close();是不是爲我工作,它的MySQL選擇查詢後的日誌形式獲取結果它將打開另一個winform(主)然後我想關閉登錄表單。我的代碼如下C#MetroFrameWork如何關閉MetroForm

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using MySql.Data.MySqlClient; 
using MetroFramework; 
using MetroFramework.Forms; 


namespace UI 
{ 
    public partial class Form1 : MetroForm 


    { 

     public static string SetFname = ""; 
     public static string Setlname = ""; 
     public Form1() 
     { 
      InitializeComponent(); 

     } 

     private void metroButton1_Click(object sender, EventArgs e) 
     { 


      try 
      { 
       string MyConnection2 = "Server=localhost;Database=Blue;Uid=root;Pwd=test123;"; 
       //Display query 
       string Query = "select * from blue.members WHERE user_name = '" + this.metroTextBox1.Text + "' AND user_pass = '" + this.metroTextBox2.Text + "' AND status = 'Activated'"; 
       MySqlConnection MyConn2 = new MySqlConnection(MyConnection2); 
       MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2); 
       // MyConn2.Open(); 
       //For offline connection we weill use MySqlDataAdapter class. 

       MySqlDataReader myReader; 
       MyConn2.Open(); 
       myReader = MyCommand2.ExecuteReader(); 




       int count = 0; 
       while (myReader.Read()) 
       { 
        count = count + 1; 


       } 
       if (count == 1) 
       { 



        string fname = myReader.GetString("firstname"); 
        string lname = myReader.GetString("lastname"); 



        MetroMessageBox.Show(this, "Log in Success! Welcome, " + fname + " " + lname + "", "Information", MessageBoxButtons.OK, MessageBoxIcon.Question); 



        Datarecords AddNew = new Datarecords(); 
        AddNew.ShowDialog(); 
        AddNew.TopMost = true; 

        this.Close(); 

       } 
       else 
       { 

        MetroMessageBox.Show(this, "Wrong Username & Password.", "Login Failed", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); 
        MyConn2.Close(); 

       } 


      } 
      catch (Exception ex) 
      { 
       MessageBox.Show(ex.Message); 
      } 


     } 
    } 
} 
+0

我試過包和關閉工作正常。 你能展示一些你的代碼嗎? –

回答

0

好了,所以環顧四周後,我發現這個解決辦法here,看來我的問題是不是與metroframework UI對不起。

1

您正在使用AddNew.ShowDialog(); 改變,要AddNew.Show();,它應該正常工作

+0

嗨,我已經改變它顯示()但仍然this.Close()不工作,我試圖把登錄窗體變成一個變量,仍然無法正常工作。 – KaoriYui