2016-04-27 1 views
1

私はC#でコーディングするのが初めてです。私のプロジェクトはWinsockコントロールを使用してサーバーとクライアントを接続しています。私はサーバーとクライアントを接続するためにこのプログラムhttp://www.go4expert.com/articles/winsock-c-sharp-t3312/を正確に実行しています。WinsockとC#の重大度tコードエラー: 'DataInput'という名前が現在のコンテキストに存在しません

形式: enter image description here

コード:

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 

namespace Winsock 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
      this.w1.Error += new AxMSWinsockLib.DMSWinsockControlEvents_ErrorEventHandler(this.w1_Error); 
      this.w1.ConnectEvent += new System.EventHandler(this.w1_ConnectEvent); 
      this.w1.DataArrival += new AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEventHandler(this.w1_DataArrival); 
     } 
     Boolean isConnect = false; 
     private void w1_ConnectEvent(object sender, EventArgs e) 
     { 
      DataInput.Text += "\n - Connect Event : " + w1.RemoteHostIP; 
      isConnect = true; 
     } 

     public void w1_Error(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ErrorEvent e) 
     { 
      DataInput.Text += "\n- Error : " + e.description; 
      isConnect = false; 
     } 

     private void w1_DataArrival(object sender, AxMSWinsockLib.DMSWinsockControlEvents_DataArrivalEvent e) 
     { 
      String data = "";  
      Object dat = (object)data; 
      w1.GetData(ref dat); 
      data = (String)dat; 
      DataInput.Text += "\nServer - " + w1.RemoteHostIP + " : " + data; 
     } 

     private void send_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       if (isConnect) 
       { 
        w1.SendData(SendText.Text); 

        DataInput.Text += "\nClent(You ;-) : " + SendText.Text; 

        SendText.Text = ""; 
       } 
       else 
        MessageBox.Show("You are not connect to any host "); 
      } 
      catch (AxMSWinsockLib.AxWinsock.InvalidActiveXStateException g) 
      { 
       DataInput.Text += "\n" + g.ToString(); 
      } 
      catch (Exception ex) 
      { 
       DataInput.Text += "\n" + ex.Message; 
      } 
     } 

     private void disconnect_Click(object sender, EventArgs e) 
     { 
      w1.Close(); 
      w1.LocalPort = Int32.Parse(portText.Text); 
      w1.Listen(); 
      DataInput.Text += "\n - Disconnected"; 
     } 

     private void Connect_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       w1.Close(); 
       w1.Connect(IPText.Text, portText.Text); 

      } 
      catch (System.Windows.Forms.AxHost.InvalidActiveXStateException g) 
      { 
       DataInput.Text += "\n" + g.ToString(); 
      } 
     } 

     private void w1_ConnectionRequest(object sender, AxMSWinsockLib.DMSWinsockControlEvents_ConnectionRequestEvent e) 
     { 
      if (isConnect == true) 
      { 
       w1.Close(); 
      } 
      w1.Accept(e.requestID); 
      isConnect = true; 
      DataInput.Text += "\n - Client Connected :" + w1.RemoteHostIP; 
     } 
    } 
} 

エラー

The name 'DataInput' does not exist in the current context

私は私を助けてくださいウェブを検索することで、この問題に対する解決策を見つけるように見えることはできません:(

+0

DataInputは、送信データに使用されるエディットコントロールの名前です。おそらくあなたのフォーム上に別の名前を付けました。 – JamieMeyer

+0

@JamieMeyer申し訳ありませんが、私は "何か他のもの"を理解することができません。私はDataInputの代わりに使用する必要があるものを意味します。 – Divi

+0

私はもう一度コードを見ました。ラベル「Get Data」の下にある大きなコントロールは、DataInputという名前にする必要があります。 – JamieMeyer

答えて

0

フォームに「DataInput」という名前のテキストボックスを作成します。

関連する問題