Extract Tool涉及到的技术

一、对文件操作

   System.IO.StreamReader sr = new System.IO.StreamReader(@"Path");

   List<information> info = JsonConvert.DeserializeObject<List<information>>(File.ReadAllText(@"Path"));//反序列化Json文件

   string json =JsonConvert.SerializeObject(newdata.ToArray(),Formatting.Indented);//将类型序列化成一个字符串

   System.IO.File.WriteAllText(filePath, json);//将一个json对象写入文件中

   System.IO.File.Delete(@"D:\information.txt");//删除该文件


二、对字符串处理

  while((str = sr.ReadLine()) != null)//从当前流中读取一行字符并将数据作为字符串返回,一行就是回车后算一行‘

   array = str.Split(',');//以逗号分隔字符串,这个C++里是没有的,本来打算是用C++处理,结果发现还真是没c#好用

  str.EndsWith("\")//判断字符串是否以"\"结尾

   str.IndexOf(',');//返回第一个逗号的位置

   str.LastIndexOf("\"")//获取最后一个“\”位置

   str.Substring(0,pos)//截取字符串

   startDt.ToString("yyyy-MM-ddTHH:mm:ss"); //转换之间格式就是这么简单,



三、JSON类属性定义

   定义在:publicpartialclassCreator : Form{}之后

publicclass data

{

publicstring Subject { get;set; }//get,set类似iOS中set,get方法,可以增加private属性

publicList<MeetingTimes> MeetingTimes;//如果json对象里数组值是一个对象,注意这里后面要加分号

}

publicclassMeetingTimes

{

publicstring Start { get;set; }

publicstring End { get;set; }

}


四、多线程套路

  创建一个带有参数的线程:

  t =newThread(newParameterizedThreadStart(compute))

    t.Start(index[a]);//传入参数

  由于一个线程无法调用非本线程中创建的控件,所以要通过多线程的方法,否则会造成UI卡死,线程阻塞

delegatevoidsubject_SetTextCallback(string text);//设置代理方法,注意命名规范

publicvoid subject_SetText(string text)

{

if(subject.InvokeRequired)//判断是否需要Invoke,如果是非本线程创建的当然要Invoke

{

subject_SetTextCallback d = newsubject_SetTextCallback(subject_SetText);//通过代理方法来调用目标方法,使用的时候直接调用目标方法就可以

this.Invoke(d,newobject[] { text });

}

else

{

this.subject.Text = text;

}

}


五、对控件的操作

创建控件

start.Location =newPoint(x1, y1);//x1,y1为控件位置

end.Location =newPoint(x2, y2);

this.Controls.Add(start);

this.Controls.Add(end);


移除控件

for (int j = 1; j <= count; j++)

{

string startStr = "start" + j.ToString();

string endStr = "end" + j.ToString();

foreach (Control c1 inthis.Controls)

{

foreach (Control c2 inthis.Controls)

if (c1.Name == startStr && c2.Name == endStr)

{

this.Controls.Remove(c1);

this.Controls.Remove(c2);

}

}

}


六、弹出对话框的使用

选取源文件

OpenFileDialog openFileDialog1 = newOpenFileDialog();//选择源文件路径

openFileDialog1.FileName =Environment.SpecialFolder.MyComputer.ToString();

if(openFileDialog1.ShowDialog() == DialogResult.OK)

{

filetxt = openFileDialog1.FileName;//获取源文件路径

sourceName.Text =Path.GetFileNameWithoutExtension(openFileDialog1.FileName);//只要文件名,不要扩展名

}


选取保存文件

SaveFileDialog saveDlg = newSaveFileDialog();

saveDlg.Filter ="文本文件|*.json";

//获取文件路径和名称,然而并不创建文件,加入第一个对象时候自动创建

if (saveDlg.ShowDialog() == DialogResult.OK)

{

filename.Text =Path.GetFileNameWithoutExtension(saveDlg.FileName);

filePath = saveDlg.FileName;

}

//弹出框

MessageBoxButtons messButton = MessageBoxButtons.OK;
DialogResult dr = MessageBox.Show("已处理完毕所有数据", "确定", messButton);
if (dr == DialogResult.OK)
{
    this.Close();
}

七、实现RichTextBox菜单及复制粘贴功能

var copyMenuItem = newMenuItem("Copy");

copyMenuItem.Click += (sender, eventArgs) => textbox.Copy();

var pasteMenuItem = newMenuItem("paste");

pasteMenuItem.Click += (sender, eventArgs) => textbox.Paste();

var contextMenu = newContextMenu();

contextMenu.MenuItems.Add(copyMenuItem);

contextMenu.MenuItems.Add(pasteMenuItem);

textbox.ContextMenu = contextMenu;


八、WinForm内嵌NodePad ++
在Creator类中

//pinvoke,调用非托管的DLL,托管的Dll是通过引用的方式加入,调用windows API

[DllImport("user32.dll")]

staticexternIntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

//DllImport Attribute 属性提供对从非托管 DLL 导出的函数进行调用所必需的信息。作为最低要求,必须提供包含入口点的 DLL 的名称。

[DllImport("user32.dll", SetLastError = true)]


Process notepad = newProcess();

ProcessStartInfo psi = newProcessStartInfo("notepad.exe");

psi.WindowStyle =ProcessWindowStyle.Normal;

notepad.StartInfo = psi;

notepad.Start();

notepad.WaitForInputIdle(3000);

//以下两个函数已声明好

Creator.SetWindowPos(notepad.MainWindowHandle,newIntPtr(-1), 0, 0, 400, 500, SWP_NOSIZE);

SetParent(notepad.MainWindowHandle,this.Handle);







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值