国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

使用C#設置系統時間(不同于以往的文章,是經過測試的)

2024-07-21 02:27:15
字體:
來源:轉載
供稿:網友

using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using system.runtime.interopservices;

namespace windowsapplication1
{
  [structlayout(layoutkind.sequential)]
  public struct systemtime
  {
    public ushort wyear;
    public ushort wmonth;
    public ushort wdayofweek;
    public ushort wday;
    public ushort whour;
    public ushort wminute;
    public ushort wsecond;
    public ushort wmiliseconds;
  }

  public class win32
  {
    [dllimport("kernel32.dll")]
    public static extern bool setsystemtime( ref systemtime systime );
    [dllimport("kernel32.dll")]
    public static extern void getsystemtime(ref systemtime systime);
  }


 /// <summary>
 /// form1 的摘要說明。
 /// </summary>
 public class form1 : system.windows.forms.form
 {
    private system.windows.forms.button button1;
    private system.windows.forms.textbox textbox1;
    private system.windows.forms.textbox textbox2;
  /// <summary>
  /// 必需的設計器變量。
  /// </summary>
  private system.componentmodel.container components = null;

  public form1()
  {
   //
   // windows 窗體設計器支持所必需的
   //
   initializecomponent();

   //
   // todo: 在 initializecomponent 調用后添加任何構造函數代碼
   //
  }

  /// <summary>
  /// 清理所有正在使用的資源。
  /// </summary>
  protected override void dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.dispose();
    }
   }
   base.dispose( disposing );
  }

  #region windows 窗體設計器生成的代碼
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void initializecomponent()
  {
      this.button1 = new system.windows.forms.button();
      this.textbox1 = new system.windows.forms.textbox();
      this.textbox2 = new system.windows.forms.textbox();
      this.suspendlayout();
      //
      // button1
      //
      this.button1.location = new system.drawing.point(188, 174);
      this.button1.name = "button1";
      this.button1.tabindex = 0;
      this.button1.text = "button1";
      this.button1.click += new system.eventhandler(this.button1_click);
      //
      // textbox1
      //
      this.textbox1.location = new system.drawing.point(56, 12);
      this.textbox1.name = "textbox1";
      this.textbox1.size = new system.drawing.size(510, 21);
      this.textbox1.tabindex = 1;
      this.textbox1.text = "textbox1";
      //
      // textbox2
      //
      this.textbox2.location = new system.drawing.point(58, 50);
      this.textbox2.name = "textbox2";
      this.textbox2.size = new system.drawing.size(506, 21);
      this.textbox2.tabindex = 2;
      this.textbox2.text = "textbox2";
      //
      // form1
      //
      this.autoscalebasesize = new system.drawing.size(6, 14);
      this.clientsize = new system.drawing.size(602, 273);
      this.controls.add(this.textbox2);
      this.controls.add(this.textbox1);
      this.controls.add(this.button1);
      this.name = "form1";
      this.text = "form1";
      this.resumelayout(false);

    }
  #endregion

  /// <summary>
  /// 應用程序的主入口點。
  /// </summary>
  [stathread]
  static void main()
  {
   application.run(new form1());
  }

    private void button1_click(object sender, system.eventargs e)
    {
      textbox1.text = datetime.now.tolongdatestring() + datetime.now.tolongtimestring();
      systemtime systime = new systemtime();

      systime.wyear = convert.touint16(datetime.now.year);
      systime.wmonth = convert.touint16(datetime.now.month);
      //處置北京時間
      int nbeijinghour = datetime.now.hour - 8;
      if (nbeijinghour <= 0)
      {
        nbeijinghour += 24;
        systime.wday= convert.touint16(datetime.now.day - 1);
        systime.wdayofweek = convert.touint16(datetime.now.dayofweek - 1);
      }
      else
      {
        systime.wday= convert.touint16(datetime.now.day);
        systime.wdayofweek = convert.touint16(datetime.now.dayofweek);
      }
      systime.whour = convert.touint16(nbeijinghour);
      systime.wminute = convert.touint16(datetime.now.minute);
      systime.wsecond = convert.touint16(datetime.now.second);
      systime.wmiliseconds = convert.touint16(datetime.now.millisecond);
 
      win32.setsystemtime(ref systime);
      textbox2.text = datetime.now.tolongdatestring() + datetime.now.tolongtimestring();
    }


 }
}


 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 左权县| 阳泉市| 盐津县| 正镶白旗| 保山市| 平罗县| 呼和浩特市| 沁源县| 吉木萨尔县| 东乡族自治县| 湛江市| 康乐县| 屏边| 历史| 南川市| 淮阳县| 定陶县| 农安县| 凉城县| 潮安县| 和龙市| 北流市| 宣威市| SHOW| 淮南市| 左贡县| 屏边| 澄城县| 海伦市| 仁化县| 安福县| 姜堰市| 如东县| 金塔县| 水城县| 洮南市| 磐安县| 太仆寺旗| 凤阳县| 新化县| 镇原县|