VB.NET 简单多线程多线程一般是不推荐用的,因为线程之间如果有共享资源的话会引起竞争,需要加锁处理;而且线程间没有时序关系,所以你在调试中可能会出现异步处理结束顺序与开始处理顺序不一致的情况(我在调试中已经发现该问题) 。
针对你提出的这个问题,采用了多线程处理,利用的是BackgroundWorker也就是异步处理控件进行了处理 。
代码已经经过调试通过 。欢迎交流,如有问题,留下QQ或其他联系方式 。
代码如下 , 并附程序截图 。
‘---------------------------------------------------
Imports System.ComponentModel '导入异步控件命名空间
Public Class Form1
Private howmany As Integer = 10
Private AnalysisNumber(0 To howmany - 1) As BackgroundWorker
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
creatNewBackgroundWorker()
addHandle()
startWork()
End Sub
Private Sub creatNewBackgroundWorker()
For i As Integer = 0 To AnalysisNumber.Length - 1
AnalysisNumber(i) = New BackgroundWorker
Next
End Sub
Private Sub addHandle()
For i As Integer = 0 To AnalysisNumber.Length - 1
AddHandler AnalysisNumber(i).DoWork, AddressOf AnalysisNumber_DoWork
AddHandler AnalysisNumber(i).RunWorkerCompleted, AddressOf AnalysisNumber_RunWorkerCompleted
Next
End Sub
Private Sub startWork()
For i As Integer = 0 To 9
Dim temp(0 To 9) As Integer
For j As Integer = 1 To 10
temp(j - 1) = 10 * ij
Next
AnalysisNumber(i).RunWorkerAsync(temp)
Next
End Sub
Private Sub AnalysisNumber_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim data As Integer()
data = https://www.04ip.com/post/CType(e.Argument, Integer())
Dim temp As Integer
For i As Integer = 0 To data.Length - 1
temp = data(i)
data(i) = temp * temp
Next
e.Result = data
End Sub
Private Sub AnalysisNumber_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs)
Dim data As Integer()
data = https://www.04ip.com/post/CType(e.Result, Integer())
For i As Integer = 0 To data.Length - 1
ListBox1.Items.Add(data(i))
Next
End Sub
End Class
VB.net简单问题Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or H80000 ' This form has to have the WS_EX_LAYERED extended style
Return cp
End Get
End Propert
上面是一个属性vb.net简单的声名
VB.net一个很简单的UI问题花了二十分钟给你写了代码,已测试 。建议学习并使用System.Drawing绘制 。
主要是掌握Graphics.FillRectangle和DrawString的使用 。
Imports System.Drawing
Public Class 进度条UI
Public 上面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 175, 238, 238))
Public 下面笔刷 As SolidBrush = New SolidBrush(Color.FromArgb(192, 30, 144, 255))
Public 文字笔 As SolidBrush = New SolidBrush(Color.FromArgb(255, 255, 255, 255))
Public 字体 As Font = New Font("微软雅黑", 14.0)
Public 文字格式 As StringFormat = New StringFormat() With
{.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
''' summary
''' 绘制指定进度的图像 。
''' 当进度变化时调用一次本方法,建议将创建的Graphics对象保存到变量而不要重复创建 。。
''' /summary
''' param name="控件"绘制到此控件的工作区/param
''' param name="g"绘制到控件的Graphics对象,例如 Button1.CreateGraphics()/param
''' param name="进度"进度百分比实数,57% = 0.57/param
Public Sub 绘制(ByRef 控件 As Control, ByRef g As Graphics, ByVal 进度 As Double)
Dim 矩形 = 控件.ClientRectangle '获取控件的工作区矩形
Dim 下面高度 = CInt(矩形.Height * 进度) '获取下面颜色块的高度
Dim 中间位置 = 矩形.Top矩形.Height - 下面高度 '获取中间分界线的Y坐标
Dim 上矩形 = New Rectangle(矩形.X, 矩形.Y, 矩形.Width, 矩形.Height - 下面高度)
Dim 下矩形 = New Rectangle(矩形.X, 中间位置, 矩形.Width, 下面高度)
g.FillRectangle(上面笔刷, 上矩形)
g.FillRectangle(下面笔刷, 下矩形)
'绘制文字
Dim 文字 As String = String.Format("{0:0.00}%", 进度 * 100)
g.DrawString(文字, 字体, 文字笔, 矩形, 文字格式)
End Sub
End Class
下面是Form1窗体的代码:添加一个Button1和Timer1控件,将Button1尺寸拖大点
Public Class Form1
Public g As Graphics
Public 进度条UI As New 进度条UI
Public 进度 As Double
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
g = Button1.CreateGraphics()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
进度= 0.01
进度条UI.绘制(Button1, g, 进度)
End Sub
End Class
【vb.net简单 vbnet imemode】关于vb.net简单和vbnet imemode的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。
推荐阅读
- 用安卓系统的按键机,安卓手机的按键失灵了该怎么办?
- 新媒体行业如何制定一个工作计划,新媒体的规划
- 区块链2019流行,最火区块链
- mysql怎么导入备份 mysql数据怎么备份
- 单机游戏显卡怎么设置不卡,游戏怎么调独立显卡
- 西部数码虚拟主机宝塔,西部数码虚拟主机退款
- 有哪些神奇的直播平台,世界上有哪些神奇的直播
- python做函数图 python画函数图像代码
- 星空拍摄设备是什么,拍摄星空出现一道痕是什么