473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Starting C#: need some help with this

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);
}
}
}

Nov 16 '05 #1
3 962
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
Nov 16 '05 #2
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
Nov 16 '05 #3
Thanks Marcin. Exactly what I was after. (Could do it with eyes closed in
VB6!).

"Marcin Hoppe" wrote:
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

Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jason Charalambides | last post by:
Hello, My question is: How do I get my application to start by double clicking on a file. I have made my application to save files with a specific extension. I associated those files to my...
12
by: serge calderara | last post by:
Dear all, I have an application which is suppose to start another executable process. As soon as that process is running, I need to retrive its handle. The problem of the particular process I am...
4
by: Adam | last post by:
Eh, probably not the most specific subject line... But, I've got a number of fields in which I need to do things like remove the first 4 characters, or remove the last 3. Such as: ...
2
by: belial | last post by:
Hi! I am new on the group and join in as i am in bad need of help in C programming.I'm a fresher and got to tackle the basics of C in the next few months,so i wonder if anyone on that group could...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
0
by: calderara serge | last post by:
Dear All, I am building an application with VB.Net that is starting an external process from my application code by using the process object. The problem I get is that the application that I...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
6
by: Arnie | last post by:
We're using the ServiceController class provided by the .NET Framework, programming in C#. We are using the Start() method to start a service from another service. This works fine most of the...
4
by: durumdara | last post by:
Hi! My problem is that: The "test.py" is working in every machine that I use except in my home machine. Formerly it worked but now not. I don't know what happened, I searching for some...
2
by: Luka Djigas | last post by:
Hello everyone, please, I need your help. I'm new to python, so I don't know if this will seem like a stupid question to some of you ... I have a need to write to a file (or just print on...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.