资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

vb.net编程例子 vb教程编程实例详解pdf

用VB.NET编写以下程序。

using System;

成都创新互联主营南康网站建设的网络公司,主营网站建设方案,App定制开发,南康h5微信小程序开发搭建,南康网站营销推广欢迎南康等地区企业咨询

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实例

1 生成txt文件。

DimSaveFileDialog1AsNewSaveFileDialog() '创建一个保存对话框

SaveFileDialog1.Filter ="txt files (*.txt)|*.txt" '设置扩展名

IfSaveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OKThen '如果确定保存

My.Computer.FileSystem.WriteAllText(SaveFileDialog1.Filename, Textbox1.Text,False) '保存文本,False表示不追加文本,直接覆盖其内容

EndIf

原文链接:

vb.net编程一个用键盘控制的东西

最简单的加速运动示例,直接拷贝代码,即可用方向键控制控件移动

Public Class 最简单的加速运动

Dim 左右, 上下 As Integer

Dim X, Y, VX, VY, VA As Double

Dim WithEvents 时钟 As New Timer

Dim WithEvents 移动控件 As New Label

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Me.KeyPreview = True

VA = 0.5

X = 300.0

Y = 300.0

移动控件.BackColor = Color.MediumPurple

移动控件.Size = New Size(60, 60)

Controls.Add(移动控件)

时钟.Interval = 25

时钟.Enabled = True

End Sub

Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown

If e.KeyCode = Keys.Up Then 上下 = -1

If e.KeyCode = Keys.Down Then 上下 = 1

If e.KeyCode = Keys.Left Then 左右 = -1

If e.KeyCode = Keys.Right Then 左右 = 1

End Sub

Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp

If e.KeyCode = Keys.Up Then 上下 = 0

If e.KeyCode = Keys.Down Then 上下 = 0

If e.KeyCode = Keys.Left Then 左右 = 0

If e.KeyCode = Keys.Right Then 左右 = 0

End Sub

Private Sub 时钟_Tick(sender As Object, e As EventArgs) Handles 时钟.Tick

VX = Math.Min(VX + 左右 * VA, 10)

VY = Math.Min(VY + 上下 * VA, 10)

X += VX

Y += VY

If X  0 Then X = 2 : VX = -VX

If Y  0 Then Y = 2 : VY = -VY

If X  Width - 移动控件.Width Then X = Width - 移动控件.Width - 2 : VX = -VX

If Y  Height - 移动控件.Height Then Y = Height - 移动控件.Height - 2 : VY = -VY

移动控件.Location = New Point(X, Y)

End Sub

End Class


本文标题:vb.net编程例子 vb教程编程实例详解pdf
网页链接:http://cdkjz.cn/article/hhcehh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220