简体   繁体   中英

C# how can I open a box to update the user on progress?

I want to open a window that will display some text like "Validating input" and hold it open until a method is finished. I can't do this with messagebox. Any ideas guys?

Unless I've misunderstood this sounds a tad cruel to the user, but you could do something like this:

A MessageBox is just a standard Windows Form shown as a modal dialog. If you don't like the controls displayed on the form then you can create your own form and show it to the user as a modal dialog through the ShowDialog method:

MyDialog dialog = new MyDialog();
dialig.ShowDialog();

Your MyDialog form can then either perform the validation itself, or respond to notification that the validation has completed. Until the dialog has been dismissed the user won't be able to interact with the rest of the app (just as when a message box is shown) and the dialog could even disable buttons / prevent the user from closing it until the validation has succeeded.

If you do this and your modal dialog isn't performing the validation then you should be aware that you will need to perform the validation on a background thread, as the UI thread will be tied up displaying the modal dialog.

You can create a basic form, and do something like this.

this.Enabled = false;
FormWaiting frm = new FormWaiting();
frm.Show();

Thread.Sleep(1000000); //Place holder for long operation.
frm.Close();
this.Enabled = true;

Depends on your app context you can pick up example of @Jethro, or

Create a your FormWaiting:Form , make it topmost and call Show() , one time your method finished execution close it.

There is a lot other stuff that you can do, but depends on yuor concrete context which can not be very clear from the post.

Hope this helps.

Regards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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