里面的WinForm C#控制台棒 [英] c# console stick inside winform

查看:85
本文介绍了里面的WinForm C#控制台棒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个学校项目,我需要创建一个Windows窗体应用程序。但对于我而言,我需要创建一个控制台应用程序。现在,我可以从通过一个按钮来打开从Windows控制台,以及一些代码,我没有完全理解。




  1. 但是,它可能在打开的同时双赢的形式打开一个控制台。



2.Could控制台是双赢的形式贴。 (如图像框。您创建面积/框,控制台保持内部的somekind的。




  1. 如何方案控制台?而不是通过在标准在项目中创建的Program.cs。



如果你能帮助我走出这将是巨大的,一直在寻找天现在...



非常感谢!


解决方案

 公共类ConsoleHelper 
{
///<总结>
///分配一个新的控制台当前进程
/// < /总结>
函数[DllImport(KERNEL32.DLL)]
公共静态外部布尔AllocConsole();

///<总结>
///释放控制台
///< /总结>
函数[DllImport(KERNEL32.DLL)]
公共静态外部布尔FreeConsole();
}

您可以调用AllocConsole创建一个控制台窗口,此时你可以使用读/写它默认的控制台方法。然后调用FreeConsole时,即可大功告成。


I have a school project where i need to create a windows form application. But for my part i need to create a console application. Now i could open a console from a windows from through a button, and some code i did not fully understand.

  1. But is it possible to open a console at the same time the win-form is opened.

2.Could the console be sticked on the win-form. ( like a image-box. you create somekind of area/box where the console stays inside.

  1. How to "program" the console? and not through program.cs that is standard created in the project.

If you could help me out that would be great, been searching for days now...

Thanks a lot!

解决方案

public class ConsoleHelper
{
    /// <summary>
    /// Allocates a new console for current process.
    /// </summary>
    [DllImport("kernel32.dll")]
    public static extern Boolean AllocConsole();

    /// <summary>
    /// Frees the console.
    /// </summary>
    [DllImport("kernel32.dll")]
    public static extern Boolean FreeConsole();
}

You can call AllocConsole to create a console window, at which point you can read/write to it using the default Console methods. Then call FreeConsole when you're done.

这篇关于里面的WinForm C#控制台棒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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