Zoro
Zoro

Reputation: 719

Cannot implicit convert type "float" to Systems.Windows.Forms.Textbox

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

Upvotes: 0

Views: 733

Answers (5)

Ehsan
Ehsan

Reputation: 32681

change it to

textBox1.Text = output.ToString();

Upvotes: 2

Yair Nevet
Yair Nevet

Reputation: 13003

This is the problem:

  private void button17_Click(object sender, EventArgs e)
    {

        textBox1 = output;
    }

What do you want to achieve?

Maybe:

  private void button17_Click(object sender, EventArgs e)
    {

        textBox1.Text = output.ToString();
    }

Upvotes: 2

Sayse
Sayse

Reputation: 43300

private void button17_Click(object sender, EventArgs e)
{

    textBox1.Text = output.ToString();
}

What the error is saying is textBox1 is a TextBox and you are trying to change this to be a Float; and there isn't any clear way of how to do this.

Most likely what you wanted to do was set the text of the textbox to be the value of the float.

Upvotes: 4

MarcinJuraszek
MarcinJuraszek

Reputation: 125620

You should assign your values to Text property:

textBox1.Text = output.ToString();

Upvotes: 2

King King
King King

Reputation: 63317

 textBox1.Text = output.ToString();

Upvotes: 3

Related Questions