C#文件同步助手

本文介绍了使用C#编程语言创建一个文件同步助手的过程,详细讲解了关键代码PUB.CS中的模块信息,帮助开发者理解如何实现文件的高效同步。
摘要由CSDN通过智能技术生成

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

拾荒网络工作室

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值