zoukankan      html  css  js  c++  java
  • UserAccountInfo时间倒计时

    界面如下:

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;

    namespace WeChatTool
    {
    public partial class UserAccountInfo : UserControl
    {
    private TimeSpan timespan = new TimeSpan(2, 0, 0);
    private double startTime;
    System.Timers.Timer timer = new System.Timers.Timer();
    public UserAccountInfo()
    {
    InitializeComponent();
    timer.Enabled = true;
    timer.Interval = 1000;
    timer.Stop();
    timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_tick);
    }

    private void UserAccountInfo_Load(object sender, EventArgs e)
    {

    }

    private void btnProduceToken_Click(object sender, EventArgs e)
    {
    string token = "";
    try
    {
    Uri url = new Uri("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx04ec9a465d7bbaf2&secret=a31fbf89aa42f984bb3f13a8bf5db949");
    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    request.Method = "GET";//默认方法是GET
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    Stream stream = response.GetResponseStream();
    StreamReader reader = new StreamReader(stream, Encoding.UTF8);
    token = reader.ReadToEnd();
    this.rtbToken.Text = token;
    Properties.Settings.Default.token = token;
    startTime = timespan.TotalSeconds;
    timer.Start();

    }
    catch (ProtocolViolationException ex)
    {
    MessageBox.Show("使用网络协议期间出错时引发的异常! " + ex.ToString(), "提示信息!", MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning);
    //throw;
    }
    }

    private void btnRefresh_Click(object sender, EventArgs e)
    {
    this.timer.Stop();
    this.btnTimer.Text = null;
    }

    private void timer_tick(object sender, System.Timers.ElapsedEventArgs e)
    {
    setTimer(startTime);
    }

    public delegate void SetTimer(double timer);

    private void setTimer(double timer)
    {
    if (this.InvokeRequired)
    {
    this.Invoke(new SetTimer(setTimer), timer);
    }
    else
    {
    DateTime datetime = new DateTime(2016,8,18,(int)(timer/3600),(int)((timer/60)%60),(int)((timer/1)%60));
    this.btnTimer.Text = datetime.ToString();
    startTime -= 1;
    }
    }

    }
    }

  • 相关阅读:
    Ubuntu16.04安装openldap和phpldapadmin
    Java 8 中的抽象类和接口到底有啥区别?
    Redis 开发陷阱及避坑指南!
    Java 中的 6 颗语法糖
    Java 8 有多牛逼?打破一切你对接口的认知!
    Git操作常用的命令都在这里了。
    Github 太狠了,居然把 "master" 干掉了!
    微服务业务日志收集方案,写得非常好!
    Maven基本介绍与安装
    IntelliJ IDEA 调试 Java 8 Stream,实在太香了!
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5813452.html
Copyright © 2011-2022 走看看