Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have developed a game using visual c# and this game saves scores in to a variable, when the user clicks on the scores button i want the messageBox that appears to display the contents of the scores variable. how do i do that? (quite new here)
code samples would help

THANKS IN ADVANCE...
Posted
Updated 27-Dec-22 17:19pm
Comments
Sergey Alexandrovich Kryukov 7-Sep-11 1:31am    
WPF, Forms or what? Tag it!
--SA

An improvement to the solution by Mika:

C#
MessageBox.Show(
    string.Format("Your score is: {0}", variable),
    string.Format(" {0}", Application.ProductName),
    MessageBoxButtons.OK, MessageBoxIcon.Information);


The use of Application.ProductName is only possible for System.Windows.Forms.

(Please always, always tag your UI library. Is it WPF or Forms?!)

For WPF, you can ether use some constant string instead (better be from resource) or create the same property using application attributes you usually write in "AssemblyInfo.cs".

—SA
 
Share this answer
 
Comments
Wendelius 7-Sep-11 1:29am    
Good answer, my 5
Sergey Alexandrovich Kryukov 7-Sep-11 1:31am    
Thank you very much, Mika.
--SA
If the score is for example in an integer variable, you could simply call:
C#
MessageBox.Show("Your score is: " + variable.ToString(), "My game",  MessageBoxButtons.OK, MessageBoxIcon.Information);

MessageBox.Show("Your score is: " + variable.ToString(), 
                Application.ProductName, 
                MessageBoxButtons.OK, 
                MessageBoxIcon.Information);
 
Share this answer
 
v2
Comments
morojele 6-Sep-11 17:31pm    
THANKS MAN IT WORKS LIKE MAGIC!!!!!!!
Wendelius 6-Sep-11 17:34pm    
No problem :) If you like, you can mark the answer as accepted.
Espen Harlinn 6-Sep-11 18:23pm    
An you can have a 5 from me :)
Wendelius 6-Sep-11 18:26pm    
Thanks Espen :)
Sergey Alexandrovich Kryukov 7-Sep-11 0:19am    
Believe or not, but I added two improvements to this code and explained the difference between Forms and WPF as the method is applicable in both. Therefore, I voted 4 for your solution :-)
--SA
private void button1_Click(object sender, EventArgs e)
{
int a, b, c;
a = Int32.Parse(textBox1.Text);
b = Int32.Parse(textBox2.Text);
c = a + b;
MessageBox.Show("Sum of a and b is="+c.ToString(),"addition of two values");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900