无法隐式转换类型“”;浮动“;到Systems.Windows.Forms.Textbox

本文关键字:浮动 Windows Textbox Forms Systems 转换 类型 | 更新日期: 2023-09-27 18:29:44

我已经尝试了一段时间,现在如何转换它。你会如何将其转换为windows形式?

它似乎不像普通的控制台应用程序那样工作。。。。

抱歉,如果这看起来很愚蠢,但我不明白。

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

无法隐式转换类型“”;浮动“;到Systems.Windows.Forms.Textbox

private void button17_Click(object sender, EventArgs e)
{
    textBox1.Text = output.ToString();
}

错误表明textBox1TextBox,而您正试图将其更改为Float;而且没有任何明确的方法来做到这一点。

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

 textBox1.Text = output.ToString();

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

textBox1.Text = output.ToString();

这就是问题所在:

  private void button17_Click(object sender, EventArgs e)
    {
        textBox1 = output;
    }

你想实现什么?

可能:

  private void button17_Click(object sender, EventArgs e)
    {
        textBox1.Text = output.ToString();
    }

将其更改为

textBox1.Text = output.ToString();