如何在messageBox上显示变量的内容 [英] How to display contents of a variable on to a messageBox

查看:70
本文介绍了如何在messageBox上显示变量的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个使用Visual C#开发的游戏,该游戏将分数保存到变量中,当用户单击分数按钮时,我希望显示显示分数变量内容的messageBox.我怎么做? (在这里非常新)
代码示例会有所帮助

提前感谢...

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...

推荐答案

Mika对解决方案的改进:

An improvement to the solution by Mika:

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



Application.ProductName仅可用于System.Windows.Forms.

(请始终始终标记您的UI库.它是WPF还是Forms ?!)

对于WPF,您可以以太(而不是从资源中)使用一些常量字符串,也可以使用通常在"AssemblyInfo.cs"中编写的应用程序属性来创建相同的属性.

—SA



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


例如,如果分数是整数变量,则可以简单地调用:
If the score is for example in an integer variable, you could simply call:
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);


这篇关于如何在messageBox上显示变量的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆