Solved

C# - Close a messageBox before displaying anther.

Posted on 2013-06-19
17
516 Views
Last Modified: 2013-06-30
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
0
Comment
Question by:ocaccy
  • 8
  • 5
  • 4
17 Comments
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 278 total points
ID: 39258932
do u control on the first messagebox being displayed?
aren't you the one who show it?
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 222 total points
ID: 39258953
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
 

Author Comment

by:ocaccy
ID: 39258982
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
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 278 total points
ID: 39259042
so before you show the first messagebox, save the message in some variable which will be used to concatenate in the second mesagebox.
0
 

Author Comment

by:ocaccy
ID: 39259107
I thought about that too. But how close the messageBox that is open to open another with the concatenate message?
0
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 278 total points
ID: 39259138
how do u open it?
Show() or ShowDialog()?
0
 

Author Comment

by:ocaccy
ID: 39259162
MessageBox.Show(
0
 

Author Comment

by:ocaccy
ID: 39259173
Also need to know how to clear the variable which will be used to concatenate messages
if the USER clicks on button messageBox?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 278 total points
ID: 39259261
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
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 222 total points
ID: 39259465
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
 

Author Comment

by:ocaccy
ID: 39259557
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
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 222 total points
ID: 39259573
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
 
LVL 42

Assisted Solution

by:sedgwick
sedgwick earned 278 total points
ID: 39259972
My mistake u right
0
 

Author Comment

by:ocaccy
ID: 39260575
Then, you guys have any suggestions for this problem?  I think if use another form like a messageBox, right?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 222 total points
ID: 39261574
>> 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
 

Author Comment

by:ocaccy
ID: 39261586
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
 

Author Closing Comment

by:ocaccy
ID: 39289070
Thank you for helping me, despite the weak explanation that I orrered them my problem.

Regards,
ocaccy
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now