我的textbox.clear();正在收到错误

时间:2012-03-14 23:05:26

标签: c# textbox onclick clear

我想要做的只是清除按钮点击上的文本框。我收到此错误

“错误2无法将类型'string'隐式转换为'System.Windows.Forms.TextBox'C:\ Users \ Ed \ Downloads \ BT1_B \ BT1_B \ Form1.cs 108 36 BT1_B “

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using InTheHand;
using InTheHand.Net;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;


namespace BT1_B
{
    public partial class Form1 : Form
    {
        Guid service = new Guid("{00001101-0000-1000-8000-00805F9B34FB}");
        BluetoothListener bl;
        BluetoothClient bc;
        bool radioAvailable = false;
        bool listening = false;
        delegate void SettbMessageReceivedCallback(string text);

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                listening = false;
                bl.Stop();
            }
            catch
            {
            }

        }

        private void btn_listen_Click(object sender, EventArgs e)
        {
            try
            {
                BluetoothRadio.PrimaryRadio.Mode = RadioMode.Discoverable;
                radioAvailable = true;
            }
            catch
            {
                MessageBox.Show("Please make sure Bluetooth is available");
            }
            if (radioAvailable)
            {
                bl = new BluetoothListener(BluetoothService.SerialPort);
                bl.Start();
                listening = true;
                System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ListenLoop));
                t.Start();
            }
        }
        private void ListenLoop()
        {
            try
            {
                while (listening)
                {
                    bc = bl.AcceptBluetoothClient();
                    StreamReader sr = new StreamReader(bc.GetStream());
                    String message = sr.ReadLine();
                    sr.Close();
                    SettbMessageReceived(message);
                }
            }
            catch
            {
            }
        }
        private void SettbMessageReceived(string text)
        {
            try
            {
                if (this.txt_incoming_message.InvokeRequired)
                {
                    SettbMessageReceivedCallback d = new SettbMessageReceivedCallback(SettbMessageReceived);
                    this.Invoke(d, new object[] { text });
                }
                else
                {
                    this.txt_incoming_message.Text += text + "\r\n";
                }
            }
            catch (ThreadAbortException ex)
            {
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btn_clear_Click(object sender, EventArgs e)
        {
            txt_incoming_message.Clear();
        }
    }
}

1 个答案:

答案 0 :(得分:3)

    private void btn_clear_Click(object sender, EventArgs e)
    {
        txt_incoming_message.Text = "";
    }

但请保持具体问题,并在寻求帮助之前做一些研究。