C# - Close a messageBox before displaying anther.

Hello everybody.
Target: XP, Vista, 7
Environment: VS2010 Ultimate, C#, WinForms.

How to add message in a messageBox previously opened in C#?
||,
How to get the message of a messageBox previously opened, close this messageBox; show another messageBox whit the previously message and show in the next line another message?

Thanks in advance,
ocaccy
ocaccyAsked:
Who is Participating?
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
>> you guys have any suggestions for this problem?

I'm really puzzled, exactly what is the problem.  Can you give an actual example of how you need this functionality.
Is your app using multiple threads (or numbers of modeless forms the user interacts with) to get data from somewhere?
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
do u control on the first messagebox being displayed?
aren't you the one who show it?
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
Typically a MessageBox will block the thread calling it until the message box is closed by the user.
Assuming you are showing the message box yourself then it makes more sense to concatenate the messages you want displayed before you show the message box.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
ocaccyAuthor Commented:
sedgwick, I use this:

MessageBox.Show(DateTime.Now.ToString("yyyy/M/d")+","+DateTime.Now.ToString("HH:mm:ss")+",Read error!");

Open in new window


Andy, I'll have some events that show messagebox, however we only allow one messageBox. Thus must concatenate the messages according to the events.
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
so before you show the first messagebox, save the message in some variable which will be used to concatenate in the second mesagebox.
0
 
ocaccyAuthor Commented:
I thought about that too. But how close the messageBox that is open to open another with the concatenate message?
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
how do u open it?
Show() or ShowDialog()?
0
 
ocaccyAuthor Commented:
MessageBox.Show(
0
 
ocaccyAuthor Commented:
Also need to know how to clear the variable which will be used to concatenate messages
if the USER clicks on button messageBox?
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
when using MessageBox.Show(), the window is not modal which means user can still interact with the main form.
is that what u want?
or do u want to force the user to click either button first?
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
This is roughly what you require:
At class level you can have a string variable.

String sMessage;
...
sMessage += "hello ";
....
sMessage += world";
....

Then to show it use a normal message box
MessageBox.Show(sMessage);  //which does show the message box as modal


And to reset it on a button press for example
sMessage = "";
0
 
ocaccyAuthor Commented:
I need that when has a event that show messageBox, before close the messageBox opened, after this show the new messageBox. If use MessageBox.ShowDialog?
0
 
AndyAinscowConnect With a Mentor Freelance programmer / ConsultantCommented:
MessageBox only supports Show (which opens it as modal, there is no modeless version - I think sedgwick mixed it up with a form which supports both variants).
0
 
Meir RivkinConnect With a Mentor Full stack Software EngineerCommented:
My mistake u right
0
 
ocaccyAuthor Commented:
Then, you guys have any suggestions for this problem?  I think if use another form like a messageBox, right?
0
 
ocaccyAuthor Commented:
Ok, I'm trying this code now!
        void messageBoxForm()
            {
            if(Application.OpenForms.OfType<MessageForm>().Count()>0)
                {
                MessageForm.ActiveForm.Disposed+=new EventHandler(closeMessageForm);
                }

            TopMost=false;
            MessageForm messageform=new MessageForm();
            messageform.ShowDialog();
            TopMost=Settings.Option.StayOnTop;
            Font=Settings.Option.MonoFont?monoFont:origFont;
            }

        private void closeMessageForm(object sender, EventArgs e)
           { MessageForm.ActiveForm.Dispose(); }

Open in new window

0
 
ocaccyAuthor Commented:
Thank you for helping me, despite the weak explanation that I orrered them my problem.

Regards,
ocaccy
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.