简体   繁体   English

Msgbox 等到,VB.NET

[英]Msgbox Wait until, VB.NET

Is it possible to have a Msgbox without a button on it in a console application.在控制台应用程序中是否可以有一个没有按钮的 Msgbox。 I would like to have a msgbox pop up and then disappear when the task has been completed.我想弹出一个消息框,然后在任务完成后消失。 Or could I send the msgboxresult to some form of window that would just disappear when the file has been written?或者我可以将 msgboxresult 发送到某种形式的 window ,当文件被写入时它会消失?

MsgBox("The users on the domain are being gathered. A prompt will appear when all information has been gathered.")
    Dim userFile2 As String = savefileDialog1.FileName & ".txt"
    Dim fileExists2 As Boolean = File.Exists(userFile2)
    Using sw As New StreamWriter(File.Open(userFile2, FileMode.OpenOrCreate))
        For Each d As DirectoryEntry In de.Children()
            sw.WriteLine(d.Name)
        Next
    End Using

If you want to have a console app with a GUI, I'd suggest that it might be easier to just make a WinForms app.如果你想拥有一个带有 GUI 的控制台应用程序,我建议只制作一个 WinForms 应用程序可能会更容易。 Just create a new tiny WinForms app, make the default Form small as a dialog box and make it have only one invisible Close button.只需创建一个新的小型 WinForms 应用程序,将默认的Form设置为小对话框,并使其只有一个不可见的Close按钮。

Then you can just show the Close button when it's finished.然后你可以在完成后显示Close按钮。

Just remember to disable the Control box on the Form (the X up in the top right hand corner) and handle any keyboard combination that could close it.请记住禁用Form上的控制框(右上角的 X)并处理任何可能关闭它的键盘组合。

Edit: Or if for any reason you have to have it as a Console app, then you could still write a tiny separate app that just does the GUI part that you need and have the Console app start up the GUI app, sending over the text to display.编辑:或者如果出于任何原因您必须将其作为控制台应用程序,那么您仍然可以编写一个单独的小型应用程序,它只执行您需要的 GUI 部分,并让控制台应用程序启动 GUI 应用程序,发送文本显示。

First, a quick point.首先,快速点。 A MsgBox is a modal dialog so will halt execution until the user responds, you can't use this. MsgBox是一个模态对话框,因此会在用户响应之前停止执行,您不能使用它。

In general "console" applications should be non-graphical.一般来说,“控制台”应用程序应该是非图形的。

You don't want to use a console application to disiplay a window.您不想使用控制台应用程序来显示 window。 Since.Net 4.0 is available to you may want a WPF application that can write to the console.由于.Net 4.0 可供您使用,您可能需要一个可以写入控制台的 WPF 应用程序。

There is a post about outputting to the console with WPF here on SO. SO上有一篇关于使用WPF输出到控制台的帖子。

You should do your work on a different thread perhaps using a System.ComponentModel.BackgroundWorker .您应该使用System.ComponentModel.BackgroundWorker在不同的线程上完成工作。 This will allow the Window to respond to user interaction and render while your task progresses.这将允许Window在您的任务进行时响应用户交互和渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM