Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2259613
  • 博文数量: 292
  • 博客积分: 10016
  • 博客等级: 中将
  • 技术积分: 3381
  • 用 户 组: 普通用户
  • 注册时间: 2005-11-06 11:26
文章分类

全部博文(292)

文章存档

2011年(1)

2010年(4)

2009年(3)

2008年(6)

2007年(47)

2006年(63)

2005年(168)

分类: C/C++

2007-05-26 21:21:25

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace Qualification
{
    public partial class FormDateSet : Form
    {
        public FormDateSet()
        {
            InitializeComponent();

        }
        //调用Kernel32.DLL

        [DllImport("Kernel32.dll")]
        public static extern void GetLocalTime(SystemTime st);
        [DllImport("Kernel32.dll")]
        public static extern void SetLocalTime(SystemTime st);


        [StructLayout(LayoutKind.Sequential)]
        public class SystemTime
        {
            public ushort wYear;
            public ushort wMonth;
            public ushort wDayOfWeek;
            public ushort wDay;
            public ushort Whour;
            public ushort wMinute;
            public ushort wSecond;
            public ushort wMilliseconds;
        
        }
        private void FormDateSet_Load(object sender, EventArgs e)
        {
           
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            SystemTime st = new SystemTime();
            GetLocalTime(st);
            this.textBox1.Text = st.wYear.ToString()+"-";
            this.textBox1.Text = this.textBox1.Text + st.wMonth.ToString() + "-";
            this.textBox1.Text = this.textBox1.Text + st.wDay.ToString() + " ";
            this.textBox1.Text = this.textBox1.Text + st.Whour.ToString() + ":" + st.wMinute.ToString() + ":" + st.wSecond.ToString();
        }

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

        private void Btn_set_Click(object sender, EventArgs e)
        {
            try
            {
                
                SystemTime st = new SystemTime();
                st.wYear = (ushort)this.dateTimePicker1.Value.Year;
                st.wMonth = (ushort)this.dateTimePicker1.Value.Month;
                st.wDay = (ushort)this.dateTimePicker1.Value.Day;
                st.Whour = (ushort)this.dateTimePicker1.Value.Hour;
                st.wMinute = (ushort)this.dateTimePicker1.Value.Minute;
                st.wSecond = (ushort)this.dateTimePicker1.Value.Second;
                SetLocalTime(st);
                MessageBox.Show("系统时间设置成功!", "系统时间设置成功!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("系统时间设置失败!", "设置失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {}
        }
    }
}

阅读(9084) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~