• 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;
    }
    }

    }
    }

  • 相关阅读:
    POJ 1436 Horizontally Visible Segments (线段树+区间覆盖)
    HDU 4671 Backup Plan (构造)
    POJ 3325 Help with Intervals (线段树(难))
    HDU 4649 Professor Tian (位运算 + 按位DP)
    HDU 4662 MU Puzzle (YY+枚举)
    HDU 4638 Group (线段树 + 离线)
    深入浅出Node.js (附录A)
    JS的变量声明和函数声明提升
    JS基础:翻转数组
    JS基础:求一组数中的最大最小值,以及所在位置
  • 原文地址:https://www.cnblogs.com/1175429393wljblog/p/5813452.html
Copyright © 2020-2023  润新知