首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >C# MetroFrameWork如何关闭MetroForm

C# MetroFrameWork如何关闭MetroForm
EN

Stack Overflow用户
提问于 2016-09-30 10:21:52
回答 2查看 2K关注 0票数 1

你好,我使用这个图书馆使用metroframework UI,但是我不能关闭一个winform -- This.Close();它不适合我,它是一个登录表单,在MySQL选择查询得到结果之后,它将打开另一个winform(Main),然后我想关闭登录表单。我的代码在下面

代码语言:javascript
复制
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);
            }  


        }
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-09-30 11:49:55

好的,在环顾四周之后,我找到了一个解决这里的方法,似乎我的问题不是metroframework UI对不起。

票数 0
EN

Stack Overflow用户

发布于 2016-09-30 10:40:57

您使用的是AddNew.ShowDialog();,将其更改为AddNew.Show();,它应该可以正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39789248

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档