Starting C#: need some help with this

  • Thread starter Thread starter Guest
  • Start date Start date
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);
}
}
}
 
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
 
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
 
Back
Top