首页 > 编程语言 >c# form主页

c# form主页

时间:2024-06-15 17:55:36浏览次数:14  
标签:sender form 主页 c# Items void private EventArgs pm

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace ProcessMonitoring
{
public partial class Form1 : Form
{
string filePath = System.Environment.CurrentDirectory + @"\data.txt";
string logPath = System.Environment.CurrentDirectory + @"\log.txt";
ProcessMonitoring pm = new ProcessMonitoring();
Form2 f2 = new Form2();
bool flag = false;//检测开关
Timer timer = new Timer();
public static List<string> lists;//要检测的值集合

public string comboBoxVal;
//
public Form1()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;


}

private void Form1_Load(object sender, EventArgs e)
{
var f2 = new Form2();

//创建文件
//获取当前程序运行的目录

pm.createFile(filePath);
pm.createFile(logPath);
//创建定时器
timer.Interval = 1000 * Form2.interval_Time;
timer.Tick += new EventHandler(start);

setCheckedListBox();

getListBoxValue();
//下拉框设置
this.comboBox1.SelectedIndex = 0;
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;

//checkedListBox1设置
this.checkedListBox1.CheckOnClick = true;

}
/// <summary>
/// setCheckedListBox设置值
///// </summary>
public void setCheckedListBox()
{
List<string> list = pm.readFile(filePath);

this.checkedListBox1.Items.Clear();
this.comboBox1.Items.Clear();
foreach (string item in list)
{
// MessageBox.Show(item);

this.checkedListBox1.Items.Add(pm.getProcessName(item));
this.comboBox1.Items.Add(pm.getProcessName(item));
}
// MessageBox.Show(this.checkedListBox1.Items.Count.ToString());
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
checkedListBox1.SetItemChecked(i, true);
}

}
/// <summary>
/// 获取选择的值
/// </summary>
public void getListBoxValue()
{
List<string> list = new List<string>();
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.GetItemChecked(i))//先判断是否被选中
{
list.Add(checkedListBox1.GetItemText(checkedListBox1.Items[i])) ;
}
}
lists = list;
}

 

//创建间隔时间

public void start(object sender, EventArgs e)
{

appRun(flag);

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

}

private void button1_Click(object sender, EventArgs e)
{
f2.ShowDialog();
}
private void appRun(bool flag)
{
if (flag)
{

foreach (string line in lists)
{


if (line != "")
{

String message = pm.findProcess(line);
if (message != "")
{
//追加message信息到log日志
string s = File.ReadAllText(logPath).Insert(0, message + "\r\n");
File.WriteAllText(logPath,s);
}


}

}
queryData(logPath);
}

}

private void button2_Click(object sender, EventArgs e)
{
// MessageBox.Show(Form2.interval_Time.ToString());
if (button2.Text=="开始检测")
{
timer.Start();
timer.Interval = 1000 * Form2.interval_Time;
button2.Text = "检测中...";

flag = true;

button2.BackColor = Color.Green;
}else
{
timer.Stop();
button2.Text = "开始检测";
flag = false;
button2.BackColor = Color.White;
}
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void queryData(string filePath)
{
string[] lines = File.ReadAllLines(filePath);
this.listBox1.Items.Clear();

foreach (string line in lines)
{

if (line != "" && this.listBox1.Items.Count <= 20)
{


this.listBox1.Items.Insert(this.listBox1.Items.Count, line);

}
}
this.listBox1.MultiColumn = true;

}

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
getListBoxValue();
}

private void refush_Click(object sender, EventArgs e)
{
setCheckedListBox();
}

private void button3_Click(object sender, EventArgs e)
{
this.listBox1.Items.Clear();
}

private void button4_Click(object sender, EventArgs e)
{
/*
foreach (var list in lists)
{
foreach (var item in pm.readFile(filePath))
{
if (list == pm.getProcessName(item))
{
pm.startProcess(pm.getProcessName(item));
}
}
}
*/


pm.startProcess(this.comboBox1.Text);
}

private void button5_Click(object sender, EventArgs e)
{
try
{
pm.startProcess(logPath);
}
catch (Exception a)
{

MessageBox.Show(a.Message.ToString());
}
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
// MessageBox.Show(this.comboBox1.SelectedValue.ToString());
}

private void button6_Click(object sender, EventArgs e)
{
pm.killProcess(this.comboBox1.Text);

pm.startProcess(this.comboBox1.Text);
}
}
}

标签:sender,form,主页,c#,Items,void,private,EventArgs,pm
From: https://www.cnblogs.com/l-xs/p/18249552

相关文章

  • c# 文件读取
    usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Threading;namespaceProcessMonitoring{publicpartialclassForm2......
  • docker没外网安装方法
    docker没外网安装方法需要先清理之前docker的依赖,避免影响安装失败1,下载docker的压缩tar包百度云Docker18.06.1地址:https://pan.baidu.com/s/1YdN9z72QutPkHBfLq06H1A密码:dvvh2,解压tar包#解压tar-xvfdocker-18.06.1-ce.tgz#将压缩的全部文件复制到/usr/bincpdoc......
  • c# excel
    usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.IO;usingSystem.Web;namespaceGetPCInformation{classExcel{publicvoidExportExcel(DataTabledt){//设置导出文件路径stringpath=HttpC......
  • Oracle 性能调优 10053事件
    思维导图10053事件概述我们在查看一条SQL语句的执行计划时,只看到了CBO最终告诉我们的执行计划结果,但是我们并不知道CBO为何要这样做。特别是当执行计划明显失真时,我们特别想搞清楚为什么CBO会做出这样的一个选择,那么就可以用10053事件来分析SQL分析过程的trace文件。同100......
  • c# 系统信息
    usingSystem;usingSystem.Windows.Forms;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Management;usingSystem.IO;usingSystem.Diagnostics;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Runtime.InteropServices;namespaceGetPCInfo......
  • 一篇文章教你如何解决vs编译器中,库函数scanf的正常使用!!!
    前言:这将是我写的第二篇博文了,以后我将会坚持每天花固定时间来写博客,希望我当我写了一定数量的文章之后,我自己简单的就能够写出质量优秀文章来,加油!!!一、scanf函数无法正常使用的原因1.错误实例在vs中如果想直接实现并使用scanf函数,很抱歉直接使用,用不了,因为编译器压根就......
  • 生产环境使用10053分析Oracle的执行计划
    【问题现象】在SQL出现性能问题后,通过分析统计信息、直方图、SQLAWR、查看执行计划等,仍然找不出为什么SQL要选择差的执行计划,就需要通过10053查看这个SQL的执行计划的更详细的信息。【操作方法】通过10053事件来查看执行计划和详细的SQL解析过程,10053的trace文件提供了Oracle......
  • 算法训练(leetcode)第九天 | 232. 用栈实现队列、225. 用队列实现栈、20. 有效的括号、1
    刷题记录232.用栈实现队列225.用队列实现栈20.有效的括号1047.删除字符串中的所有相邻重复项232.用栈实现队列leetcode题目地址考察栈与队列之间的特性。栈:后进先出(先进后出)——FILO。队列:先进先出——FIFO。所以使用两个栈模拟队列,分别为in和out。当入队新......
  • Docker 入门
    Docker是一个开源的应用容器引擎,它允许开发者打包他们的应用以及应用的运行环境到一个可移植的容器中。以下是学习Docker的推荐路线:###入门阶段1.**了解容器化的概念**:  -容器化与虚拟化的区别  -容器化的优势2.**Docker简介**:  -Docker的历史和目标......
  • C++学习手册
    创建一份全面的C++学习手册是一个庞大的任务,但这里我可以为你提供一个基础的大纲和一些关键点,以帮助你开始学习C++。###C++学习手册大纲####第一部分:C++简介1.C++的历史与发展2.C++的特点3.C++的应用领域4.开发环境的搭建####第二部分:基础语法1.基本数据类型2......