簡體   English   中英

C#MetroFrameWork如何關閉MetroForm

[英]C# MetroFrameWork how to Close a MetroForm

您好,我正在通過該使用Metroframework UI,但無法關閉Winform This.Close();。 對我不起作用,它是MySQL選擇查詢得到結果后的登錄表單,它將打開另一個winform(Main),然后我要關閉登錄表單。 我的代碼如下

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


        }
    }
}

您正在使用AddNew.ShowDialog(); 將其更改為AddNew.Show(); 它應該可以正常工作

好了,環顧四周后,我在這里找到了解決方法,看來我的問題不是Metroframework UI對此感到抱歉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM