关于程序中的索引超出数组界限怎么解决

沧海1梦 2017-03-18 10:11:14
一个C#的客户端程序,在本地模拟服务器后,可以建立socket通信,但是刚接受数据后,会,运行到 “this.Text += "\n" + RecvTemp[1];”提示索引超出数组界限,请大家帮忙看下,代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Client;
using Maticsoft.Model;
using DevComponents.DotNetBar;

namespace Balloon
{
/// <summary>
/// Summary description for AlertCustom.
/// </summary>
public class AlertCustom : DevComponents.DotNetBar.Balloon
{
/// <summary>
/// Required designer variable.
/// </summary>
// int userState;
private System.ComponentModel.Container components = null;
private TextBox textBox1;
string temp;
string MessageSN = "0";
private DevComponents.DotNetBar.ButtonItem buttonItem3;
private DevComponents.DotNetBar.Bar bar1;
private DevComponents.DotNetBar.ButtonItem buttonItem2;
private DevComponents.DotNetBar.ButtonItem buttonItem4;

public AlertCustom()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

public AlertCustom(string str)
{
InitializeComponent();
temp = str; // this.frmManager = frmManager;

// CheckState(planState);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.textBox1 = new System.Windows.Forms.TextBox();
this.buttonItem3 = new DevComponents.DotNetBar.ButtonItem();
this.bar1 = new DevComponents.DotNetBar.Bar();
this.buttonItem2 = new DevComponents.DotNetBar.ButtonItem();
this.buttonItem4 = new DevComponents.DotNetBar.ButtonItem();
((System.ComponentModel.ISupportInitialize)(this.bar1)).BeginInit();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(1, 141);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(10, 21);
this.textBox1.TabIndex = 0;
this.textBox1.Visible = false;
//
// buttonItem3
//
this.buttonItem3.ItemAlignment = DevComponents.DotNetBar.eItemAlignment.Far;
this.buttonItem3.Name = "buttonItem3";
this.buttonItem3.Text = "Options...";
//
// bar1
//
this.bar1.BackColor = System.Drawing.Color.Transparent;
this.bar1.Font = new System.Drawing.Font("宋体", 9F);
this.bar1.Items.AddRange(new DevComponents.DotNetBar.BaseItem[] {
this.buttonItem2,
this.buttonItem4});
this.bar1.Location = new System.Drawing.Point(74, 137);
this.bar1.Name = "bar1";
this.bar1.Size = new System.Drawing.Size(102, 25);
this.bar1.Stretch = true;
this.bar1.Style = DevComponents.DotNetBar.eDotNetBarStyle.Office2007;
this.bar1.TabIndex = 3;
this.bar1.TabStop = false;
this.bar1.Text = "bar1";
this.bar1.Visible = false;
//
// buttonItem2
//
this.buttonItem2.ForeColor = System.Drawing.Color.Red;
this.buttonItem2.Name = "buttonItem2";
this.buttonItem2.Text = "未处理";
this.buttonItem2.Click += new System.EventHandler(this.buttonItem2_Click_1);
//
// buttonItem4
//
this.buttonItem4.ForeColor = System.Drawing.Color.Blue;
this.buttonItem4.ItemAlignment = DevComponents.DotNetBar.eItemAlignment.Center;
this.buttonItem4.Name = "buttonItem4";
this.buttonItem4.Text = "处理";
this.buttonItem4.Click += new System.EventHandler(this.buttonItem4_Click_1);
//
// AlertCustom
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
this.BackColor2 = System.Drawing.Color.FromArgb(((int)(((byte)(201)))), ((int)(((byte)(217)))), ((int)(((byte)(239)))));
this.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(101)))), ((int)(((byte)(147)))), ((int)(((byte)(207)))));
this.CaptionFont = new System.Drawing.Font("Tahoma", 8F, System.Drawing.FontStyle.Bold);
this.CaptionText = "即时通讯";
this.ClientSize = new System.Drawing.Size(255, 165);
this.Controls.Add(this.bar1);
this.Controls.Add(this.textBox1);
this.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(76)))), ((int)(((byte)(76)))));
this.Location = new System.Drawing.Point(0, 0);
this.Name = "AlertCustom";
this.Style = DevComponents.DotNetBar.eBallonStyle.Office2007Alert;
this.Load += new System.EventHandler(this.AlertCustom_Load);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.AlertCustom_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.bar1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();

}
#endregion



private void AlertCustom_FormClosing(object sender, FormClosingEventArgs e)
{
string[] RecvTemp = temp.Split('|');
USER_IP data = new USER_IP();
data.USER_DOMAIN = Environment.UserDomainName;
data.USER_ID = Environment.UserName;
data.MESSAGESN = "1";
data.WF_NAME = RecvTemp[3];
data.USER_STATE = RecvTemp[1];
Frmain.SendUpConnectCommand(data);

// MESSAGEDATA mesdata = new MESSAGEDATA();
// mesdata.TO_USERID = Environment.UserName;
// mesdata.TYPE = "1";
//// MessageSN = "1";
// mesdata.WF_NAME = RecvTemp[3];
// Frmain.SendUpConnectCommand(mesdata);

// this.Close();
}

private void AlertCustom_Load(object sender, EventArgs e)
{
this.TopMost = true;
//Rectangle r = System.Windows.Forms.SystemInformation.VirtualScreen;
Rectangle r = Screen.GetWorkingArea(this);
this.Location = new Point(r.Right , r.Bottom);
this.AutoClose = true;
this.AlertAnimation = eAlertAnimation.BottomToTop;
this.AlertAnimationDuration = 300;
// this.Text = temp;
string[] RecvTemp = temp.Split('|');
this.Text = RecvTemp[0];
this.Text += "\n" + RecvTemp[1];
this.Text += "\n" + RecvTemp[2];
this.Text += "\n" + RecvTemp[3];
}
...全文
656 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Poopaye 2017-03-18
  • 打赏
  • 举报
回复
说明temp里没有|

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧