如何在C#中的智能设备(移动应用程序)中附加文本(文本) [英] HOW to appendtext (text) in Smart Device(MOBILE APPLICATION) in C#

查看:68
本文介绍了如何在C#中的智能设备(移动应用程序)中附加文本(文本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了用于使用C#(移动应用程序)从智能设备中的串行端口读取数据的代码,因为我可以获得可用的COM端口,我还可以在将数据发送到com端口时连接和断开端口,因为我无法传输从发送文本框到接收文本框的数据.我要在此处粘贴发送按钮的代码,因为我不能将数据附加到智能设备中,而在C#窗口窗体中以相同的代码工作.请发送代码以进行附加,将文本发送文本框到接收文本框*

在我的代码中具有
我在其中使用了两个标签
一个可用COM端口的标签
第二个用于连接和断开连接的标签显示在此标签上
一个combox
三个按钮(连接,断开连接,发送)
一个Rich文本框
一个文本框



i write code for reading data from serial port in smart device using C#(mobile application) in that i get the available COM Ports, i can also connecting and disconnecting the ports when sending data to com ports in that i can not transfer the data from sending text Box To Receiving text Box. write code for send button i am pasting here in that i can,t appending the data in smart device same code working C# window forms pl send code for append, text sending text Box To Receiving text Box*

in my code having
i used Two Labels in that
one Label for Available COM Ports
second Label for connect and disconnect show on this label
one combox
three buttons (connect,disconnect,send)
one Rich text box
one text box



        //THSI IS SMART DEVICE PROJECT USING c#
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SerialPort port = new SerialPort();
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                #region Display all available COM Ports
                string[] ports = SerialPort.GetPortNames();
                // Add all port names to the combo box:
                foreach (string port in ports)
                {
                    //this.cboPortName.Items.Add(port);
                    this.cbbCOMPorts.Items.Add(port);
                }
                #endregion
                this.btnDisconnect.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnConnect_Click_1(object sender, EventArgs e)
        {
            if (port.IsOpen)
            {
                port.Close();
            }
            try
            {
                {
                    port.PortName = cbbCOMPorts.Text;
                    port.BaudRate = 96000;
                    port.Parity = Parity.None;
                    port.DataBits = 8;
                    port.StopBits = StopBits.One;
                }
                //.Encoding = System.Text.Encoding.Unicode 
                port.Open();
                lblMessage.Text = cbbCOMPorts.Text + " Connected. ";
                btnConnect.Enabled = false;
                btnDisconnect.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            txtDataToSend.Focus();
        }
        private void btnDisconnect_Click_1(object sender, EventArgs e)
        {
            try
            {
                port.Close();
                lblMessage.Text = port.PortName + " disconnected.";
                btnConnect.Enabled = true;
                btnDisconnect.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                port.Write(txtDataToSend.Text);
                //txtDataReceived->IS a data Received Text Box name 
               //txtDataToSend->is a data send Text Box name

                txtDataReceived.AppendText (txtDataToSend.Text ); // <<---- error here
                txtDataReceived.Text = txtDataReceived.Text + txtDataToSend.Text;//<--- i Tried but it not error but data cannot be appendtext in text box(txtDataReceived)
                txtDataReceived.ScrollToCaret();
               }
               txtDataToSend.Text = string.Empty;
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }

       }



< -----------------------错误消息----------------------- >
-----当我编译或运行该项目时,它显示以下错误------
"System.Windows.Forms.TextBox"不包含"AppendText"的定义,也没有扩展方法"AppendText"接受类型为"System.Windows"的第一个参数可以找到".Forms.TextBox"(您是否缺少using指令或程序集引用?)



<-----------------------ERROR MESSAGE ----------------------->
-----WHEN I COMPILE OR RUN THE PROJECT IT SHOWING THE BELOW ERROR------
''System.Windows.Forms.TextBox'' does not contain a definition for ''AppendText'' and no extension method ''AppendText'' accepting a first argument of type ''System.Windows.Forms.TextBox'' could be found (are you missing a using directive or an assembly reference?)

推荐答案

不是您已发布您收到的错误消息,我在"C#TextBox对象"上进行了搜索,在MSDN站点上,我发现TextBox.AppendText()在使用.Net 3.5或更高版本之前不可用.
您正在使用.Net 3.0 ...

错误消息告诉您该方法根本不在TextBox类中.
Not that you''ve posted the error message you''re getting, I googled "C# TextBox object", and on the MSDN site, I found that TextBox.AppendText() is not available until you use .Net 3.5 or higher.

You''re using .Net 3.0...

The error message is telling you that the method simply isn''t in the TextBox class.


JSOP,AppendText实际上一直追溯到.Net 1.0.该人员可能正在使用的.Net CF中只是没有此功能.就像我之前说的,解决方案是:
JSOP, AppendText actually goes all the way back to .Net 1.0. It is just not available in .Net CF, which this person is likely using. Like I said before, the solution is to do:
txtDataReceived.Text = txtDataReceived.Text + txtDataToSend.Text;


这不会导致编译时错误.如果是这样,请发布该错误的内容,我们将为您提供进一步的帮助.您仅发布了AppendText的错误,而不是此代码行的错误.


That will not cause a compile time error. If it does, then post what that error is and we can assist you further. You have only posted the error for AppendText, not for this line of code.


以下行是导致此错误的原因:
The following line is what is causing the error:
txtDataReceived.AppendText (txtDataToSend.Text );


以下行未引起错误:


The following line is NOT causing the error:

txtDataReceived.Text = txtDataReceived.Text + txtDataToSend.Text;


删除第一行并将其替换为第二行.不要只添加第二行.您需要删除第一行.


REMOVE the first line and replace it with the second line. Do not just add the second line. You need to REMOVE THE FIRST LINE.


这篇关于如何在C#中的智能设备(移动应用程序)中附加文本(文本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆