富文本框问题

扫码查看
本文介绍了富文本框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友,

这是我的代码来说明问题:

Hi Friends,

Here is my code to illustrate the problem:

namespace NetworkTool.Ping
{
  public partial class Network_Tool_Form : Form
  {
    public Network_Tool_Form()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {}

     string iP = "192.168.1.1";


    private void pingButton_Click(object sender, EventArgs e)
    {
      pingsSent = 0;
      pingResultRichTextBox.Clear();
      pingResultrichTextBox.Text += "Pinging " + iP + " with 32 bytes of data:\r\n\r\n";

       //HERE THE MESSAGE DISPLAYED ON RICHTEXTBOX CORRECTLY.  :-\ 
      SendPing();
      //IT GIVES ME "", ALTHOUGH IT WAS THE SAME PREVIOUS MESSAGE. :confused: 
      pingResultrichTextBox.Text += messageDisplay;
    }

     private int pingsSent;
     AutoResetEvent resetEvent = new AutoResetEvent(false);
     private string messageDisplay = "";

        private void SendPing()
        {
            Ping pingSender = new Ping();
            pingSender.PingCompleted += new PingCompletedEventHandler (pingSender_Complete);
            byte[] packetData = Encoding.ASCII.GetBytes("................................");
            PingOptions packetOptions = new PingOptions(64, true);
            pingSender.SendAsync(iP, 12000, packetData, packetOptions, pingObject.resetEvent);
        }

        private void pingSender_Complete(object sender, PingCompletedEventArgs e)
        {
          if (e.Error != null)
          {
            // AT THIS point MY RICHTEXTBOX DISPLAY THE MESSAGE.  :-\ 
            pingResultrichTextBox.Text += "An error occured: ";

            //BUT IF I PASSED THE MESSAGE TO THE STRING VARIABLE AND TRY TO DISPLAY THE STRING VARIABLE IT DOSEN"T GOT THE MESSAGE.  :doh:              
            messageDisplay = "An error occured: ";
            ((AutoResetEvent)e.UserState).Set();

          }
        }
  }
}





[原标题]
我在富文本框"上显示文本时遇到问题.





[orig title]
I face a problem for displaying a text on RICH TEXT BOX.

推荐答案


System.Net.NetworkInformation.PingCompletedEventHandler PingCompleted
Occurs when an asynchronous operation to send an Internet Control Message Protocol (ICMP) echo message and receive the corresponding ICMP echo reply message completes or is canceled.


这篇关于富文本框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 05:30
查看更多