VB.NET按钮开始、暂停、继续实例(附带C#代码)
该实例并不一定是最正确计算方式,毕竟每个程序员的思路不同,用的方法也不同,该方法只是简单的逻辑思维,用处:可以拿以前淋漓发布的那两个刷帖助手做演示,利用该例程,可以在写刷帖软件时候,通过按钮的暂停继续事件来控制从列表框中依次循环,直到点击停止才停止刷帖……
演示步骤:按钮默认为“开始”,点击一次后变成“正在进行中”,这时候开始执行事件,如代码中这个循环数字(可以把循环数字这个事件换成别的,如循环列表框等),再次点击按钮,按钮名变为“继续”,这时候循环暂停,最后再点击按钮,按钮则又变成“正在进行中”,循环则继续接着上次运行;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Static linli As Integer
If Button1.Text = "开始" Or Button1.Text = "继续" Then
Button1.Text = "正在进行中"
Do Until Button1.Text = "继续"
linli = linli + 1
TextBox1.Text = linli
Application.DoEvents()
Loop
Else
Button1.Text = "继续"
End If
End Sub
End Class |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "开始" || button1.Text == "继续")
{
button1.Text = "正在进行中";
for (int linli = textBox1.Text == "" ? 0 : int.Parse(textBox1.Text); button1.Text == "正在进行中"; linli++)
{
textBox1.Text = linli.ToString();
Application.DoEvents();
}
}
else
{
button1.Text = "继续";
}
}
}
} |
VB.NET编译出的例子下载地址:http://pan.baidu.com/s/1qWkFBHy
此后本博客会时不时发布些编程思路和我所能想到的有用的功能实现方法,VB.NET在网上的资源少,很多时候我们都需要不断积累才能更加巩固。


