• 大小: 157KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-04
  • 语言: C#
  • 标签: NTP  时间同步  

资源简介

自动从NTP服务器获取时间并同步本地时间,新测可用,C#,WinForm

资源截图

代码片段和文件信息

using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace SyncTime
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender EventArgs e)
        {
            Program.msgTxt = msgTxt;
            XBtn.PerformClick();
            
            bool autoGet = Properties.Settings.Default.AutoGet;
            bool autoSync = Properties.Settings.Default.AutoSync;
            autoGetChk.Checked = autoGet;
            autoSyncChk.Checked = autoSync;

            if (autoSync)
            {
                if (setTimeZone() && setTime())
                {
                    // 最小化窗口
                    this.WindowState = FormWindowState.Minimized;
                    // 隐藏任务栏图标
                    this.ShowInTaskbar = false;
                    // 启动自动退出线程
                    Thread exitThread = new Thread(exitProgram);
                    exitThread.IsBackground = true;
                    exitThread.Start();
                }
                else
                {
                    autoSyncChk.Checked = false;
                }
            }
            else if (autoGet)
            {
                if (!setTimeZone() || !getTime())
                {
                    autoGetChk.Checked = false;
                }
            }
        }

        private void XBtn_Click(object sender EventArgs e)
        {
            if(“>“ == XBtn.Text)
            {
                this.MaximumSize = new Size(700 300);
                this.MinimumSize = new Size(700 300);
                this.Width = 700;
                XBtn.Text = “<“;
                getBtn.Focus();
            }
            else
            {
                this.MaximumSize = new Size(373 300);
                this.MinimumSize = new Size(373 300);
                this.Width = 373;
                XBtn.Text = “>“;
                getBtn.Focus();
            }
        }

        private void notifyBtn_MouseClick(object sender MouseEventArgs e)
        {
            // 鼠标左键点击托盘图标
            if (e.Button == MouseButtons.Left)
            {
                if (this.WindowState == FormWindowState.Minimized)
                {
                    // 禁止程序自动退出
                    Program.exitFlag = false;
                    //还原窗体
                    this.WindowState = FormWindowState.Normal;
                    //系统任务栏显示图标  
                    this.ShowInTaskbar = true;
                }
                //激活窗体并获取焦点  
                this.Activate();
            }
        }

        private void autoGetChk_CheckedChanged(object sender EventArgs e)
        {
            Properties.Settings.Default.AutoGet = autoGetChk.Checked;
            Properties.Settings.Default.Save();
        }

        private void autoSyncChk_CheckedChanged(obj

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1042  2017-10-03 19:36  SyncTime\App.config

     文件      56320  2018-12-27 09:41  SyncTime\bin\Debug\SyncTime.exe

     文件       1042  2017-10-03 19:36  SyncTime\bin\Debug\SyncTime.exe.config

     文件      42496  2018-12-27 09:41  SyncTime\bin\Debug\SyncTime.pdb

     文件      22696  2018-12-27 09:42  SyncTime\bin\Debug\SyncTime.vshost.exe

     文件       1042  2017-10-03 19:36  SyncTime\bin\Debug\SyncTime.vshost.exe.config

     文件        490  2018-04-12 07:35  SyncTime\bin\Debug\SyncTime.vshost.exe.manifest

     文件      55808  2017-10-04 21:34  SyncTime\bin\Release\SyncTime.exe

     文件       1042  2017-10-03 19:36  SyncTime\bin\Release\SyncTime.exe.config

     文件      38400  2017-10-04 21:34  SyncTime\bin\Release\SyncTime.pdb

     文件      22696  2017-10-04 21:34  SyncTime\bin\Release\SyncTime.vshost.exe

     文件       1042  2017-10-03 19:36  SyncTime\bin\Release\SyncTime.vshost.exe.config

     文件        490  2017-03-19 05:00  SyncTime\bin\Release\SyncTime.vshost.exe.manifest

     文件      10627  2017-10-04 21:17  SyncTime\MainForm.cs

     文件      12368  2017-10-04 14:56  SyncTime\MainForm.Designer.cs

     文件      35490  2017-10-04 14:56  SyncTime\MainForm.resx

     文件       1779  2017-10-03 21:52  SyncTime\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7217  2018-12-27 09:41  SyncTime\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       1314  2018-12-27 09:42  SyncTime\obj\Debug\SyncTime.csproj.FileListAbsolute.txt

     文件       1015  2017-10-04 21:34  SyncTime\obj\Debug\SyncTime.csproj.GenerateResource.Cache

     文件       2384  2017-10-04 21:34  SyncTime\obj\Debug\SyncTime.csprojResolveAssemblyReference.cache

     文件      56320  2018-12-27 09:41  SyncTime\obj\Debug\SyncTime.exe

     文件      20188  2017-10-04 21:34  SyncTime\obj\Debug\SyncTime.MainForm.resources

     文件      42496  2018-12-27 09:41  SyncTime\obj\Debug\SyncTime.pdb

     文件        180  2017-10-04 21:34  SyncTime\obj\Debug\SyncTime.Properties.Resources.resources

     文件          0  2017-10-03 19:13  SyncTime\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2017-10-03 19:13  SyncTime\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2017-10-03 19:13  SyncTime\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       1464  2017-10-04 15:23  SyncTime\obj\Release\DesignTimeResolveAssemblyReferences.cache

     文件       7171  2017-10-04 14:57  SyncTime\obj\Release\DesignTimeResolveAssemblyReferencesInput.cache

............此处省略37个文件信息

评论

共有 条评论