尝试下一步 - 我想检查某些信息是否已经存在,如果 csv 文件,如果是 - 打开带有标签的表单,然后从文件代码中放入此标签信息代码是下一个:
public void getEventTime(string filePath, string currDate, string currentDateTimeHM)
{
//reading the *.csv file and convert to the array of data
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
//create array for getting any vlaue from string
string[] arrOfData = sr.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
sr.Close();
List<string> lines = new List<string>();
bool status=false;//variable for showing form if event exist
foreach (var l in arrOfData)
{
if (l.Contains(currDate) && l.Contains(currentDateTimeHM))
{
string[] temp = l.Split(',').Take(5).ToArray();
notLabel.Text = temp[1].ToString();
status = true;
}
}
if (status)
{
//show Notification Form
Form NotificationForm = new Notification();
NotificationForm.Visible = true;
}
}
一切正常 - 如果信息存在 - 新表单打开,但这notLabel.Text = temp[0].ToString();
部分没有返回任何内容。在调试期间我得到了下一个
意味着代码是正确的但对我来说很奇怪的原因导致程序 - 没有这个文本。我在哪里犯了一些错误?
下面的表格带有标签
检查
文件 NotificationDesigner.Form.cs 中的几行
this.notLabel.AutoSize = true;
this.notLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(204)));
this.notLabel.Location = new System.Drawing.Point(12, 22);
this.notLabel.Name = "notLabel";
this.notLabel.Size = new System.Drawing.Size(34, 13);
this.notLabel.TabIndex = 0;
this.notLabel.Text = "label";