当表单2关闭时,form1中的提示消息框 [英] Prompt message box in form1 when form 2 is close

查看:79
本文介绍了当表单2关闭时,form1中的提示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我遇到了关于C#.NET的问题。这就是事情。这个概念就像您在Microsoft Word中保存文档一样,将显示savedialog。用户将键入名称,然后保存到相应的文件夹。



我的问题是我使用自己的Windows窗体提示而不是saveialog表单,我想在messagebox中显示输入的值。这是代码。



Form2

Hi. I'm having a problem regarding C#.NET. Here is the thing. The concept is like you saving document in Microsoft word and the savedialog will appear. User will key-in the name and it is then save to the respective folder.

My problem is that I am using my own windows form to prompt out instead of savedialog form and I want to show the value of input in messagebox. here is the code.

Form2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DynamicSimulator_v2
{
    public partial class SchemaName : Form
    {
        private string data;

        public SchemaName()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            data=txtDB.Text;
            this.Hide();
        }

        public string getData()
        {
            return data;
        }

    }
}





表格1



Form 1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MySql.Data;
using MySql.Data.MySqlClient;

namespace DynamicSimulator_v2
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnNew_Click(object sender, EventArgs e)
        {
            SchemaName schemaForm = new SchemaName();
            schemaForm.Show();

            if () //I'm stuck at this part. I would like to do something like this
//  if ( schemaForm.Show() == System.Windows.Forms.Button btnOK )

            {
                MessageBox.Show(schemaForm.getData());   
            }
            /*
                       string connStr = "datasource=localhost;port=3306;username=root;password=root;";
                       MySqlConnection conn = new MySqlConnection(connStr);
                        try
                        {
                           conn.Open();
                           MySqlCommand cmdDatabase = new MySqlCommand("CREATE SCHEMA @schema; ", conn);
            
                           cmdDatabase.Parameters.AddWithValue("@schema", data.getSchema());
                           MySqlDataReader myReader;
        
                            myReader = cmdDatabase.ExecuteReader();
                            myReader.Close();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message); 
                        }
                        conn.Close();
           
                    }*/
        }
    }
}





我这样做的主要目的是将字符串值从其他表单传递到另一个表单,并使用字符串值作为mysql数据库的模式名称。



The main purpose I do this is to passing string value from other form to another form and used the the string value as the schema name for mysql database.

推荐答案

尝试:

Try:
SchemaName schemaForm = new SchemaName();
if (schemaForm.ShowDialog() == DialogResult.OK)
   {
   ...
   }

并设置DialogResult属性确定按钮。

and set the DialogResult property of the OK button.


这篇关于当表单2关闭时,form1中的提示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆