![](/img/trans.png)
[英]C# NO Mapping exists from object type systems.windows.forms.textbox
[英]Cannot implicit convert type “float” to Systems.Windows.Forms.Textbox
我已經嘗試了一段時間了,如何轉換它。 您將如何在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;
}
}
private void button17_Click(object sender, EventArgs e)
{
textBox1.Text = output.ToString();
}
錯誤的意思是textBox1
是一個TextBox
並且您試圖將其更改為Float
; 而且沒有明確的方法來做到這一點。
您最想做的是將文本框的文本設置為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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.