C# 窗口程序
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Configuration;
namespace 文件同步
{
public partial class Form1 : Form
{
private const int WM_HOTKEY = 0x312; //窗口消息:热键
private const int WM_CREATE = 0x1; //窗口消息:创建
private const int WM_DESTROY = 0x2; //窗口消息:销毁
private const int HotKeyID = 1; //热键ID(自定义)
public static bool WindowState = true;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
button3_Click_1(null, null);
this.Stations.Parent = this.pictureBox1;//设置Stations标签的背景透明
}
catch
{
MessageBox.Show("需要安装 Net.Framework3.5 才可以运行此程序!");
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
PUB.flag="exit";
System.Environment.Exit(0); // 这是最彻底的退出方式,不管什么线程都被强制退出,把程序结束的很干净。
}
private void button3_Click_1(object sender, EventArgs e)
{
PUB.strSource = PUB.GetAppConfig("src"); //原路径
PUB.strObjective = PUB.GetAppConfig("obj"); //目标路径
PUB.synTime = Convert.ToInt32(PUB.GetAppConfig("synTime"));
textBox1.Text = PUB.strSource;
textBox2.Text = PUB.strObjective;
textBox3.Text = PUB.synTime.ToString();
}
private void button1_Click_1(object sender, EventArgs e)
{
//基本设置
try { PUB.synTime = Convert.ToInt32(PUB.GetAppConfig("synTime")); }
catch
{
MessageBox.Show("配置的同步时间格式不正确!"); return;
}
textBox3.Text = PUB.synTime.ToString();
if (Directory.Exists(PUB.strSource) == false) { MessageBox.Show("配置的原路径不存在!"); return; }
if (Directory.Exists(PUB.strObjective) == false) { MessageBox.Show("配置的目标路径不存在!"); return; }
PUB.strState = "n";
if (PUB.strState == "n")
{
PUB.strState = "ok";
PUB.flag = "ok";
PUB.bound = false;
}
else
{
PUB.strState = "ok";
PUB.flag = "ok";
PUB.bound = true;
}
Thread thread = new Thread(new ThreadStart(PUB.ThreadProc));
PUB.threadShow = new Thread(new ThreadStart(PUB.ThreadShow));
thread.Start();
PUB.threadShow.Start(); //开始线程
PUB.threadShow.Suspend(); //挂起线程
button1.Enabled = false;
}
private void button2_Click_1(object sender, EventArgs e)
{
button3_Click_1(null, null);
MessageBox.Show("配置完成,重启程序后生效!");
System.Environment.Exit(0); // 这是最彻底的退出方式,不管什么线程都被强制退出,把程序结束的很干净。
}
private void button4_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择源文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
this.textBox1.Text = foldPath;
}
}
private void button5_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择目标文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dial
C#文件同步助手
最新推荐文章于 2024-06-04 21:58:59 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)