C# winfrom设置循环暂停和继续 原文转自:http://blog.csdn.net/qwldcl/article/details/3970784...

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

namespace WindowsFormsApplication1
{
    public partial class Form12 : Form
    {

        public enum RunState
        {
            running,
            pause,
            stop
        }

        private int i = 0;

        RunState state = RunState.stop;  


        public Form12()
        {
            InitializeComponent();
        }

        private void RunProc(object sender, EventArgs e)//执行的部分   
        {
            timer1.Enabled = false;
            if (state == RunState.running)
            {
                label1.Refresh();
                label1.Text = "";
                label1.Text = i.ToString();
                label1.Refresh();
                i++;
                timer1.Enabled = true;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.button1.Text == "开始")
            {
                this.button1.Enabled = false;
                this.button2.Enabled = true;
                this.button3.Enabled = true;

                timer1.Tick += new EventHandler(RunProc);
                timer1.Enabled = true;

                this.state = RunState.running;
            }  
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.button2.Text == "暂停")
            {
                timer1.Enabled = false;
                state = RunState.pause;

                this.button2.Text = "继续";
            }
            else
            {
                timer1.Enabled = true;
                this.state = RunState.running;
                this.button2.Text = "暂停";
                this.button2.Enabled = true;
                //timer1.Start();   
            }  

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.timer1.Enabled = false;
            this.i = 0;
            this.label1.Text = "0";
            this.state = RunState.stop;

            this.button1.Text = "开始";
            this.button1.Enabled = true;
            this.button2.Text = "暂停";
            this.button2.Enabled = false;
            this.button3.Enabled = false;  

        }

        private void Form12_Load(object sender, EventArgs e)
        {
            this.label1.Text = "0";
            this.button2.Enabled = false;
            this.button3.Enabled = false;
        }
    }
}

转载于:https://www.cnblogs.com/wuhuisheng/archive/2011/08/10/2133466.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用C#的`HttpClient`类来调用WebService接口,并传递参数和接收返回值。以下是一个示例代码: ```csharp using System; using System.Net.Http; using System.Text; using System.Threading.Tasks; using System.Xml; namespace WebServiceExample { class Program { static async Task Main(string[] args) { // 接口地址 string url = "http://10.10.47.132:8103/soap/IWebService"; // 创建HttpClient对象 HttpClient client = new HttpClient(); // 创建SOAP请求内容 string soapRequest = @"<?xml version=""1.0"" encoding=""utf-8""?> <soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""> <soap:Body> <YourMethodName xmlns=""YourNamespace""> <Param1>Value1</Param1> <Param2>Value2</Param2> </YourMethodName> </soap:Body> </soap:Envelope>"; // 设置请求头部信息 client.DefaultRequestHeaders.Add("SOAPAction", "YourSOAPAction"); // 发送请求并获取响应 HttpResponseMessage response = await client.PostAsync(url, new StringContent(soapRequest, Encoding.UTF8, "text/xml")); // 读取响应内容 string responseContent = await response.Content.ReadAsStringAsync(); // 解析XML响应 XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(responseContent); // 提取返回值 XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable); nsManager.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/"); nsManager.AddNamespace("ns", "YourNamespace"); XmlNode resultNode = xmlDoc.SelectSingleNode("//ns:YourMethodNameResponse/ns:YourMethodNameResult", nsManager); string result = resultNode.InnerText; // 输出返回值 Console.WriteLine("返回值: " + result); } } } ``` 你需要将上述代码中的以下部分进行替换: - `url`:将其替换为你的WebService接口地址。 - `soapRequest`:将其替换为你的SOAP请求内容。 - `"YourMethodName"`:将其替换为你要调用的WebService方法名。 - `"YourNamespace"`:将其替换为你的命名空间。 - `"YourSOAPAction"`:将其替换为你的SOAPAction。 请确保你的应用程序具有访问WebService接口的权限,并根据实际情况修改代码以适应你的需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值