English 中文(简体)
说明案文的法典
原标题:Code to show a string of text
  • 时间:2011-11-09 01:05:04
  •  标签:
  • c#
  • winforms

在我上学的第一个学期,我会再读C#。 我必须做一个可在Celsius和Fahrenheit之间转换的Winforms。 我的代码(基本)全部下降,但我需要把结果结果贴上标签。 我可以用<代码>lblOutput = 产出.ToString();发送标签的答案,但我需要诸如“[输出]Celsius将是法赫雷特”。 我试图在“走向”之后放在方括号中,但我正在发现一个错误。

除此以外,我还有其他一切。 我一直在寻找最后几天来加以说明,但我无法找到答案。 非常感谢任何帮助。

Edit:

我制定的法典载于纽特。 我有两个无线电台,他说,装入正文箱的价值要么是法特,要么是法尔,要么是Cels,要么是Cels,要么是“&”;

这是我在纽芬兰的法典。 如果有任何改进办法,请让我知道。

private void btnConvert_Click(object sender, EventArgs e)
{
    decimal Input = Convert.ToDecimal(txtInput.Text); //grabs the input that the user entered

    if (rbtnCelsius.Checked == true) //Test to see if the Celsius radio button is checked
    {
        decimal Output = ((Input - 32) * 5) / 9; //If yes, it uses this formula to convert the input from Farenheit to Celsius
        txtOutput.Text = Output.ToString(); //Outputs the message to the user, showing the Celsius end point
    }
    else //Says that the Celsius Radio Button is not checked, meaning that the Farenheit radio button is
    {
        decimal Output = (Input * 9) / 5 + 32; //Moves onto this formula, converts Celsius to Farenheit
        txtOutput.Text = Output.ToString(); //outputs the message to the user, showing the Farenheit end point
    }

    //txtOutput.Text = Output.ToString();
    //Commented out because it gives an error saying that "Output does not exist in current context"
}
问题回答
int fahrenheit, celsius;
// your code to set the two variables
string yourLabelText = String.Format("{0} Celcius is {1} Fahrenheit", celsius.ToString(), fahrenheit.ToString());

yourLabel.Text = yourLabelText;

这里指的是“努力”。 格式。 (与Lukazoid一样!)

我不知道你是否关注这一问题,但在某些情形下,你可以通过打电话<Output.ToString()来获取12.2433333等内容,使之更加方便用户使用。

Output.ToString("F2")

这将改为12.24。 您可以与string一起使用。 表格与民间建议一样。

我不肯定你的问题是什么,但如果你需要把产出纳入你能够做到的短语。

private void btnConvert_Click(object sender, EventArgs e)
{
    decimal Input = Convert.ToDecimal(txtInput.Text); //grabs the input that the user entered
    // declare this outside the loop so you can use it later.
    decimal output = 0M;
    if (rbtnCelsius.Checked == true) //Test to see if the Celsius radio button is checked
    {
        output= ((Input - 32) * 5) / 9; //If yes, it uses this formula to convert the input from Farenheit to Celsius

    }
    else //Says that the Celsius Radio Button is not checked, meaning that the Farenheit radio button is
    {
        output= (Input * 9) / 5 + 32; //Moves onto this formula, converts Celsius to Farenheit

    }

    txtOutput.Text =string.Format("{0} Celsius will is {1} Fahrenheit",input,output);
}`

p.s. 不要忘记使用一种试样法,以确保 t酸化能够被无限期地转换成ci。

你可以使用扼杀手段。 替换像{0}或{1}等症状的形式,或者你可以直接使用扼杀。 我不想直接给你回答,因为你说这是家事,但如果你想一例,你就能够找到你的方法。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签