0

What is a good way to code a messagebox in C#, like the AfxMessageBox in used in Visal C++?

Also, is there a good way to write information out to a log file?

7
Contributors
13
Replies
14
Views
9 Years
Discussion Span
Last Post by cVz
0

i can help with the message box question,
the snippet below is used to create a dialog box :

string message = "blah";
string caption = "blah";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;

result = MessageBox.Show(message, caption, buttons, icon);

0

then you just write event handlers for the yes/no buttons.
e.g. for yes:

if (result == System.Windows.Forms.DialogResult.Yes)
{
this.Close();
}

you may have guessed this dialog box can be used for a "are you sure you want to quit" scenario. hope this helps

0

i can help with the message box question,
the snippet below is used to create a dialog box :

string message = "blah";
string caption = "blah";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;

result = MessageBox.Show(message, caption, buttons, icon);

There must be some sort of "using ..."
declaration missing.

I got a compile error:
error CS0246: The type or namespace name 'MessageBoxButtons' could not be found (are you missing a using directive or an assembly reference?)

0

>The type or namespace name 'MessageBoxButtons' could not be found
Are you getting the same error for MessageBox? They're in the same namespace: System.Windows.Forms.

0

using System.Windows.Forms;
fixed the problem.

I got this compile message:
error CS0103: The name 'MessageBox' does not exist in the current context

But not now.
Muchas Gracias

0

im having a problem with the MessageBox's yes and no option

either button i clicked, it does not close right away, but will only do so on the second click. so if i had put any code within the yes or no click, it gets executed twice because of this

by the way, my messagebox appears when i click a cell inside the datagridview object because i placed a delete icon there in 1 column

0

I'd debug the DialogResult to see what or how many you're getting back. It could also be that the messagebox is being displayed twice when the cell click event is fired. If that is the case, either debug the click event or add a bool to only allow the messagebox to be displayed once.

0

i got it. the event handler was added twice. still ... it should have overwritten it if i added it twice... not have 2 event handlers

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.