包含vb.net测试程序实例的词条
用VB.NET编写以下程序。
using System;
创新互联是一家专注于成都网站设计、网站制作与策划设计,二道江网站建设哪家好?创新互联做网站,专注于网站建设10余年,网设计领域的专业建站公司;建站业务涵盖:二道江等地区。二道江做网站价格咨询:18980820575
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Timer tm = new Timer();//实例化 timeer
static int timeS = 0; //设置静态变量记录秒数
TimeSpan ts = new TimeSpan(); //实例化 TimeSpan
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
tm.Interval = 1000; //设置 timeer 1000毫秒执行一次
tm.Tick += new EventHandler(timeer_Tick); //设置 timeer 运行事件
tm.Start(); // 启用 timeer
}
private void timeer_Tick(object sender, EventArgs e)
{
timeS += 1; //秒数 +1
ts = new TimeSpan(0, 0, timeS);
label1.Text = ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds;
}
private void button2_Click(object sender, EventArgs e)
{
tm.Stop();
timeS = 0;
}
}
}
VB.net生成单个实例应用程序
就是只允许启动单一个应用程序的实例, 试图启动第二次时不会产生新的实例,并激活已经启动的实例.
关于VB.NET进度条的实例
该实例有很多实现方法,下面介绍一种不同的给你:
首先要在窗体中载入以下控件:progressbar(进度条),label(用来实时显示文本提示),两个timer(分别控制进度条进度的增减),然后用以下代码就能实现:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 500
Timer2.Interval = 500
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
ProgressBar1.Minimum = 0
End Sub
'上述过程是设置控件的初始值,也可以在属性面板设置
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Value += 1
Label1.Text = "当前完成" ProgressBar1.Value "%"
If (ProgressBar1.Value = 100) Then
Timer1.Enabled = False
Timer2.Enabled = True
End If
End Sub
'timer1用来控制进度的增加
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
ProgressBar1.Value -= 1
Label1.Text = "当前完成" ProgressBar1.Value "%"
If (ProgressBar1.Value = 0) Then
Timer1.Enabled = True
Timer2.Enabled = False
End If
End Sub
'time2用来控制进度的减少
End Class
网站栏目:包含vb.net测试程序实例的词条
链接地址:http://ybzwz.com/article/heohgj.html