Console.Write不工作在Win Forms应用程序 [英] Console.Write Not Working In Win Forms App

查看:124
本文介绍了Console.Write不工作在Win Forms应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2008中创建了一个VB.NET窗体应用程序。当我从命令行运行我的程序,我没有输出(只有下一个提示)。

I created a VB.NET Windows Forms Application in Visual Studio 2008. When I run my program from the command-line, I get no output (only the next prompt).

我做错了什么?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Debug.Write("Foo")
    Debug.Flush()
    Console.WriteLine("foo")
    Console.Beep(800, 100) 'confirm this function is called'
    Me.Close()
End Sub

EDIT:程序可以有表单和控制台吗?

Can a program have a form and a console?

EDIT2:但是,输出将显示在下一个命令行提示符下。

Ho's answer works. However, the output appears on the next command-line prompt. Can a Winforms application tell the command-line to wait until it's finished instead of immediately returning?

推荐答案

或者如果你已经有一个命令行, WinForms应用程序可以使用AttachConsole API将控制台附加到它。

Or if you already have a WinForms application you can attach a Console to it using the AttachConsole API.

using System.Runtime.InteropServices;  

...

[DllImport("kernel32.dll")] static extern bool AttachConsole(int dwProcessId);
private const int ATTACH_PARENT_PROCESS = -1;  

...

AttachConsole(ATTACH_PARENT_PROCESS);

(格式化为代码)

这篇关于Console.Write不工作在Win Forms应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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