You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Cigarette/WindowsFormsApp2/Alarm_Record.cs

62 lines
2.8 KiB
C#

2 years ago
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;
using System.IO;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using System.Net.NetworkInformation;
namespace WindowsFormsApp2
{
public partial class Alarm_Record : Form
{
public Alarm_Record()
{
InitializeComponent();
}
public void UpdateDialog()
{
this.listView1.BeginUpdate(); //数据更新UI暂时挂起直到EndUpdate绘制控件可以有效避免闪烁并大大提高加载速度
this.listView1.View = View.Details; //显示方式(注意View是Details详细显示)
this.listView1.GridLines = true; //行和列是否显示网格线
this.listView1.LabelEdit = true; //是否可编辑
this.listView1.Scrollable = true; //没有足够的空间显示时,是否添加滚动条
this.listView1.HeaderStyle = ColumnHeaderStyle.Clickable; //对表头进行设置
this.listView1.FullRowSelect = true; //是否可以选择行
this.listView1.MultiSelect = false; //禁止多选
this.listView1.Columns[3].Width = 0; //用于隐藏第四列的指令标号 不让用户看见
this.listView1.Clear(); //从控件中移除所有项和列(包括列表头)
this.listView1.Columns.Add("报警开始时间", 120, HorizontalAlignment.Left);
this.listView1.Columns.Add("报警处理时间", 120, HorizontalAlignment.Left);
this.listView1.Columns.Add("报警信息", 120, HorizontalAlignment.Left);
this.listView1.Columns.Add("报警代码", 120, HorizontalAlignment.Left);
string path = @"alarm.txt";
if (File.Exists(path))
{
foreach (string text in System.IO.File.ReadLines(path))
{
if (text.IndexOf('_') != -1)
{
string[] str = text.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
ListViewItem list = new ListViewItem(); //新建ListViewItem对象list
list.SubItems.Add(str[0]);
list.SubItems.Add(str[1]);
list.SubItems.Add(str[2]);
list.SubItems.Add(str[3]);
this.listView1.Items.Add(list);
}
}
}
this.listView1.EndUpdate(); //结束数据处理UI界面一次性绘制。
}
}
}