1

All I want to do is just clear the text box on a button click. I get this error

"Error 2 Cannot implicitly convert type 'string' to '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();
        }
    }
}
braX
  • 11,506
  • 5
  • 20
  • 33
Ed Briscoe
  • 117
  • 1
  • 9

1 Answers1

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

but please keep the question specific, and do some research before asking for help.

Lyuben Todorov
  • 13,987
  • 5
  • 50
  • 69
  • are you sure its a textbox ? please (if possible) post code of the designer class where you've created the textbox and/or a link to an image of the form – Lyuben Todorov Mar 14 '12 at 23:30
  • private System.Windows.Forms.TextBox txt_incoming_message; – Ed Briscoe Mar 14 '12 at 23:31
  • This answer is correct, you couldn't be getting the same error. – NetMage Mar 14 '12 at 23:49
  • i found this [question](http://stackoverflow.com/questions/1217772/c-sharp-put-string-into-textbox) which suggest that there was a threading problem. – Lyuben Todorov Mar 14 '12 at 23:50
  • What does without threading mean? This code was just given to us by tutors so we could develop and android app that would send data to the text box but I would like to add extra functionality to my already working program to clear the textbox. I do not know C#. – Ed Briscoe Mar 14 '12 at 23:57
  • Screenshot Form1.cs, the line that gives the error. I can't imagine how this could be failing. – CptSupermrkt Mar 15 '12 at 00:12
  • The ListenLoop method is in it's own thread and passes the message variable to another thread (the main thread). Without clearing that text box does the code compile and run ? Also why are you using a try catch if you dont catch an exception ? And finaly the code above clears the textbox, i've no idea why you are getting the error you are getting. The issue is not comming from the way you are clearing the textbox. For now i wish you good luck, and hope you resolve the issue. – Lyuben Todorov Mar 15 '12 at 00:15
  • If it's just a blue squiggly line under the 'xt', try compiling anyway. Sometimes even when you make a correction in Visual Studio, it doesn't stop notifying you about the now-corrected error until you compile. Happens to me every so often. – CptSupermrkt Mar 15 '12 at 00:17
  • 1
    You guys are a incredibly kind and brilliant. Thank you to everyone, wish you all the best in whatever you do. – Ed Briscoe Mar 15 '12 at 00:27