保存按钮和进度条不同步,请帮忙修改下
怎么实现显示%?
此主题相关图片如下:1.png
Dim Result As DialogResult
Result = MessageBox.Show("保存数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = MainTable.Rows.Count '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
For i As Integer = 0 To MainTable.Rows.Count - 1
MainTable.Rows(i)("序号") = i
If i Mod 500 = 0 Then
p.Value = i '当前值为已经完成的行数
End If
For Each dt As DataTable In DataTables
dt.Save()
MessageBox.Show("数据正在保存!请稍候", "提示")
Next
Next
MessageBox.Show("数据保存完成!", "提示")
Else
MessageBox.Show("数据未保存,请注意保存!", "提示")
End If
[此贴子已经被作者于2024/3/7 16:27:09编辑过]
Dim Result As DialogResult
Result = MessageBox.Show("保存数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
MessageBox.Show("数据正在保存!请稍候", "提示")
dim cnt as integer = DataTables.Count
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = cnt '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
For i As Integer = 0 To cnt - 1
dt.Save()
p.Value = i
p.Label= format(i / cnt ,"0%")
Application.DoEvents
Next
MessageBox.Show("数据保存完成!", "提示")
Else
MessageBox.Show("数据未保存,请注意保存!", "提示")
End If
错误代码: p.Label = format(i / cnt , "0%")
保存开始时进度条一直没动,直到保存结束才动,没走到头
此主题相关图片如下:2.png
Dim Result As DialogResult
Result = MessageBox.Show("保存数据?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Result = DialogResult.Yes Then
MessageBox.Show("数据正在保存!请稍候", "提示")
Dim cnt As Integer = DataTables.Count
Dim p As WinForm.ProgressBar
p = e.Form.Controls("ProgressBar1")
p.Maximum = cnt '设置最大值
p.Minimum = 0 '设置最小值
p.Value = 0 '设置当前值
For i As Integer = 0 To cnt - 1
For Each dt As DataTable In DataTables
dt.Save()
p.Value = i
'p.Label = format(i / cnt , "0%")
Application.DoEvents
Next
Next
MessageBox.Show("数据保存完成!", "提示")
Else
MessageBox.Show("数据未保存,请注意保存!", "提示")
End If
p.Value = 0 '设置当前值
dim i as integer = 0
For Each dt As DataTable In DataTables
dt.Save()
p.Value = i
i = i+1
Application.DoEvents
Next
MessageBox.Show("数据保存完成!", "提示")