我在这个codeproject站点找到了控件:

Console Control

我在form1设计器工具箱中添加了dll,并将控制台控件拖到了form1 . 但我面临两个问题 .

第一个是当我从硬盘上运行文件opengrads.exe时双击它我看到它的原始输出文本应该如下:

Console Window

但是当使用控制台控件时,我看到里面的是这个奇怪的红色和白色文本:

Console Control1

在这两种情况下,我可以在控件内输入我需要的命令,但它们正在工作,但为什么我在控制台控件中看到我拖动form1这个红色和白色文本?它来自哪里?为什么我在运行opengrads.exe时看不到原始文本?

这是我的代码:

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 System.IO;
using System.Net;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace Grads_Scripts
{
    public partial class Form1 : Form
    {
        string cmd = "";
        string exepath = @"C:\OpenGrADS\Contents\Cygwin\Versions\2.0.2.oga.2\i686\";

        public Form1()
        {
            InitializeComponent();

            cmd = "set xsize 650 500";
            ProcessCommands();
        }

        private void ProcessCommands()
        {
            consoleControl1.StartProcess(exepath + "opengrads.exe", cmd);
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}

此控制台控件存在两个问题:

  • 当我在运行opengrads.exe时,我在控制台控件中看到不同的文本和颜色,而不是原始显示的内容(第一个截图图片)?

  • 我正在使用cmd变量我在那里添加了一个命令“set xsize 650 500”但是我没有看到它在控制台控制窗口中没有任何改变 . 如果我将自己键入命令,它将执行它但使用cmd变量它什么也不做 . 如何向此consoleControl1发送命令?