首页 > 解决方案 > 为什么在c#中从.dll调用时表单不出现

问题描述

.dll 文件中的这个命名空间
这个.dll 来检查是否存在某些文件
以及如果文件存在。检查文件的内容

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CheckData
{



public class CheckFileContent : Form
{
    public  void Check(Form  CreateFile)
    {

        try
        {

            // check file if exsits
            if (!System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConReq.HP"))
            {
               CreateFile = new Form();
               CreateFile.ShowDialog();
            }
            else
            {
                //If file exists.Check the content of the file

                string[] lines = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConReq.HP");

检查第一行内容是否为特定单词(DBname=)

                if (lines[0].Substring(0, 7) != "DBname=")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }

检查第一行是否包含特定单词(DBname =)

                else if (lines[0].Substring(7, lines[0].Length - 7) == "")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }

检查第一行内容是否为特定单词(server=)

                else if (lines[1].Substring(0, 7) != "Server=")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }

检查第一行是否包含特定的单词(server=)

                else if (lines[1].Substring(7, lines[1].Length - 7) == "")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }

检查第一行内容是否特定单词(数据源=)

                else if (lines[2].Substring(0, 12) != "Data Source=")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }

检查第一行是否包含特定单词(数据源=)

                else if (lines[2].Substring(12, lines[2].Length - 12) == "")
                {
                    CreateFile = new Form();
                    CreateFile.ShowDialog();
                }
            }
        }
        catch (Exception check_e)
        {
            MessageBox.Show(check_e.Message, check_e.Source, MessageBoxButtons.OK);
            Application.Exit();
        }
    }
}

当在主窗体中调用 .dll 并调用方法来检查文件是否存在时

CheckFileContent cheek = new CheckFileContent();
        cheek.Check(CheckFileCon.ActiveForm);

当文件不存在时,此表单调用以创建新文件 我想要这个

但这 就是我得到的

标签: c#

解决方案


推荐阅读