0

I have been trying for a little while now how to convert this. How would you cast this in windows forms?

It doesnt seem to work like normal console applications....

Sorry if this seems dumb but I don't understand it.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

 namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
    float input1 = 0;
    float input2 = 0;
    float output = 0;

    int c = 0;


    public Form1()
    {
        InitializeComponent();

    }

    private void button10_Click(object sender, EventArgs e)
    {
        textBox1.AppendText("0");
    }

    private void button11_Click(object sender, EventArgs e)
    {
        textBox1.Clear();
    }

    private void button17_Click(object sender, EventArgs e)
    {

        textBox1 = output;
    }

    private void button12_Click(object sender, EventArgs e)
    {

         switch(c)
         {
             case '+': 
                 output = input1 + input2;

                 break;      
         }
    }
4

5 回答 5

4
private void button17_Click(object sender, EventArgs e)
{

    textBox1.Text = output.ToString();
}

错误所说的textBox1是 a TextBox,而您正试图将其更改为 a Float; 并且没有任何明确的方法可以做到这一点。

很可能您想要做的是将文本框的文本设置为浮点值。

于 2013-08-30T15:50:52.957 回答
3
 textBox1.Text = output.ToString();
于 2013-08-30T15:50:41.880 回答
2

您应该将值分配给Text属性:

textBox1.Text = output.ToString();
于 2013-08-30T15:50:51.220 回答
2

这就是问题:

  private void button17_Click(object sender, EventArgs e)
    {

        textBox1 = output;
    }

你想达到什么目标?

也许:

  private void button17_Click(object sender, EventArgs e)
    {

        textBox1.Text = output.ToString();
    }
于 2013-08-30T15:51:11.830 回答
2

将其更改为

textBox1.Text = output.ToString();
于 2013-08-30T15:51:19.617 回答