Starting C#: need some help with this

G

Guest

This should be easy for a C# programmer.
In the code below:
1. how do I modify the code for the Msg function to return a result (the
button clicked)?
2. how do I trap the value in the Main function?

Thank you.
using System;
using System.Windows.Forms;
namespace mine
{
public class personal
{
public static void Main()
{
/* Calculation code goes here */
Msg ("Calculation Complete. Update database?");
/* DAtabase update code */
}
public static void Msg(string message)
{
MessageBox.Show (message, "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
}
}
 
M

Marcin Hoppe

AA2e72E napisał(a):
This should be easy for a C# programmer.
In the code below:
1. how do I modify the code for the Msg function to return a result (the
button clicked)?
2. how do I trap the value in the Main function?

Thank you.
using System;
using System.Windows.Forms;
namespace mine
{
public class personal
{
public static void Main()
{
/* Calculation code goes here */
Msg ("Calculation Complete. Update database?");
/* DAtabase update code */
}
public static void Msg(string message)
{
MessageBox.Show (message, "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);
}
}
}

I guess that you want to perform some action if the user click OK. It
can be easily achieved as MessageBox.Show method returns one of the
values defined in DialogResult enumeration. Therefore your can change
your code to something similar to this:

using System;
using System.Windows.Forms;

namespace mine
{
public class personal
{
public static void Main()
{
if(Msg("Calculation Complete. Update database?") == DialogResult.OK)
{
// Do smth.
}
}

public static DialogResult Msg(string message)
{
return MessageBox.Show( message,
"My application",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk);
}
}
}

Regards,
Marcin
 
M

Marcin Hoppe

AA2e72E napisał(a):
This should be easy for a C# programmer.
In the code below:
1. how do I modify the code for the Msg function to return a result (the button clicked)?
2. how do I trap the value in the Main function?

Thank you.
using System;
using System.Windows.Forms;
namespace mine
{
public class personal
{
public static void Main() {
/* Calculation code goes here */
Msg ("Calculation Complete. Update database?");
/* DAtabase update code */
}
public static void Msg(string message)
{
MessageBox.Show (message, "My Application",
MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk);


I guess that you want to perform some action if the user click OK.
It can be easily achieved as MessageBox.Show method returns one of the
values defined in DialogResult enumeration. Therefore your can change
your code to something similar to this:

using System;
using System.Windows.Forms;

namespace mine
{
public class personal
{
public static void Main()
{
if(Msg("Calculation Complete. Update database?") ==
DialogResult.OK)
{
// Do smth.
}
}

public static DialogResult Msg(string message)
{
return MessageBox.Show( message,
"My application",
MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk);
}
}
}

Regards,
Marcin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top