How to display message box without any buttons in C#
Asked Answered
R

4

6

I try to show a MESSAGE to the user while an operation is executed. The MESSAGE won't show any button. Just a MESSAGE (text) and maybe a background image.

The problem is the following:

  • MessageBox does not seem to be the good control (because of button and it blocks the running process).
  • Form.ShowDialog() also blocks the running process. I don't know what to do.
  • I want to show the message, run my process, and dispose the message when the process is done.

How to achieve this in C# ?

Ridings answered 16/7, 2012 at 10:19 Comment(0)
S
8

Create a simple form with the message (or expose a public property to be able to change the message, or a constructor with message parameter to pass it in) and show the form using this Show overload. Then disable the (entire) original (owner) form (or just disable the controls you don't want accesible).

So, in your "main" form do this:

Form f = new MessageForm();
f.Show(this);         //Make sure we're the owner
this.Enabled = false; //Disable ourselves
//Do processing here
this.Enabled = true;  //We're done, enable ourselves
f.Close();            //Dispose message form

Also, consider using a BackgroundWorker.

Stanleigh answered 16/7, 2012 at 10:22 Comment(2)
How to do this using C++/CLR?Feudalize
@Feudalize Define "this"? The backgroundworker? Showing a form with setting an owner? What have you tried? Did you search?Stanleigh
P
2

create custom form, and write own behavior

P answered 16/7, 2012 at 10:21 Comment(0)
S
0

Create a custom form set it to minimal styles etc. Make sure it knows when the process is complete, say by passing in a reference to the process and checking it every now and then.

Sclerous answered 16/7, 2012 at 10:23 Comment(0)
C
0

One way you could do it is create a worker class that raises an event when it is finished.

execute the worker class in a new thead so it runs it the backgroud.

create the modal form with a method to close it as the event handler for the "finished" event. This way the ui still works and responds and the form will close once the worker thread is finished.

Cramer answered 16/7, 2012 at 10:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.