• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET ToolStripProgressBar类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.Windows.Forms.ToolStripProgressBar的典型用法代码示例。如果您正苦于以下问题:VB.NET ToolStripProgressBar类的具体用法?VB.NET ToolStripProgressBar怎么用?VB.NET ToolStripProgressBar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ToolStripProgressBar类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: FibonacciNumber

' 导入命名空间
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.ComponentModel



Class FibonacciNumber
   Inherits Form
   
   <STAThread()>  _
   Shared Sub Main()
      Application.EnableVisualStyles()
      Application.Run(New FibonacciNumber())
   End Sub    
   Private progressStatusStrip As StatusStrip
   Private toolStripProgressBar As ToolStripProgressBar
   Private requestedCountControl As NumericUpDown
   Private goButton As Button
   Private outputTextBox As TextBox
   Private backgroundWorker As BackgroundWorker
   Private toolStripStatusLabel As ToolStripStatusLabel
   Private requestedCount As Integer
   
   
   Public Sub New()
      [Text] = "Fibonacci"
      
      ' Prepare the StatusStrip.
      progressStatusStrip = New StatusStrip()
      toolStripProgressBar = New ToolStripProgressBar()
      toolStripProgressBar.Enabled = False
      toolStripStatusLabel = New ToolStripStatusLabel()
      progressStatusStrip.Items.Add(toolStripProgressBar)
      progressStatusStrip.Items.Add(toolStripStatusLabel)
      
      Dim flp As New FlowLayoutPanel()
      flp.Dock = DockStyle.Top
      
      Dim beforeLabel As New Label()
      beforeLabel.Text = "Calculate the first "
      beforeLabel.AutoSize = True
      flp.Controls.Add(beforeLabel)
      requestedCountControl = New NumericUpDown()
      requestedCountControl.Maximum = 1000
      requestedCountControl.Minimum = 1
      requestedCountControl.Value = 100
      flp.Controls.Add(requestedCountControl)
      Dim afterLabel As New Label()
      afterLabel.Text = "Numbers in the Fibonacci sequence."
      afterLabel.AutoSize = True
      flp.Controls.Add(afterLabel)
      
      goButton = New Button()
      goButton.Text = "&Go"
      AddHandler goButton.Click, AddressOf button1_Click
      flp.Controls.Add(goButton)
      
      outputTextBox = New TextBox()
      outputTextBox.Multiline = True
      outputTextBox.ReadOnly = True
      outputTextBox.ScrollBars = ScrollBars.Vertical
      outputTextBox.Dock = DockStyle.Fill
      
      Controls.Add(outputTextBox)
      Controls.Add(progressStatusStrip)
      Controls.Add(flp)
      
      backgroundWorker = New BackgroundWorker()
      backgroundWorker.WorkerReportsProgress = True
      AddHandler backgroundWorker.DoWork, AddressOf backgroundWorker1_DoWork
      AddHandler backgroundWorker.RunWorkerCompleted, AddressOf backgroundWorker1_RunWorkerCompleted
      AddHandler backgroundWorker.ProgressChanged, AddressOf backgroundWorker1_ProgressChanged
   End Sub 
    
   
   Private Sub backgroundWorker1_DoWork(sender As Object, e As DoWorkEventArgs)
      ' This method will run on a thread other than the UI thread.
      ' Be sure not to manipulate any Windows Forms controls created
      ' on the UI thread from this method.
      backgroundWorker.ReportProgress(0, "Working...")
      Dim lastlast As [Decimal] = 0
      Dim last As [Decimal] = 1
      Dim current As [Decimal]
      If requestedCount >= 1 Then
         AppendNumber(0)
      End If
      If requestedCount >= 2 Then
         AppendNumber(1)
      End If
      Dim i As Integer
      
      While i < requestedCount
         ' Calculate the number.
         current = lastlast + last
         ' Introduce some delay to simulate a more complicated calculation.
         System.Threading.Thread.Sleep(100)
         AppendNumber(current)
         backgroundWorker.ReportProgress(100 * i / requestedCount, "Working...")
         ' Get ready for the next iteration.
         lastlast = last
         last = current
         i += 1
      End While
      
      
      backgroundWorker.ReportProgress(100, "Complete!")
    End Sub
   
   
   Delegate Sub AppendNumberDelegate(number As [Decimal])
   
   Private Sub AppendNumber(number As [Decimal])
      If outputTextBox.InvokeRequired Then
         outputTextBox.Invoke(New AppendNumberDelegate(AddressOf AppendNumber), number)
      Else
         outputTextBox.AppendText((number.ToString("N0") + Environment.NewLine))
      End If
   End Sub 
   Private Sub backgroundWorker1_ProgressChanged(sender As Object, e As ProgressChangedEventArgs)
      toolStripProgressBar.Value = e.ProgressPercentage
      toolStripStatusLabel.Text = e.UserState '
   End Sub 
   
   
   Private Sub backgroundWorker1_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
      If TypeOf e.Error Is OverflowException Then
         outputTextBox.AppendText((Environment.NewLine + "**OVERFLOW ERROR, number is too large to be represented by the decimal data type**"))
      End If
      toolStripProgressBar.Enabled = False
      requestedCountControl.Enabled = True
      goButton.Enabled = True
   End Sub 
    
   
   Private Sub button1_Click(sender As Object, e As EventArgs)
      goButton.Enabled = False
      toolStripProgressBar.Enabled = True
      requestedCount = Fix(requestedCountControl.Value)
      requestedCountControl.Enabled = False
      outputTextBox.Clear()
      backgroundWorker.RunWorkerAsync()
   End Sub 
End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:144,代码来源:ToolStripProgressBar



注:本文中的System.Windows.Forms.ToolStripProgressBar类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET ToolStripStatusLabel类代码示例发布时间:2022-05-26
下一篇:
VB.NET ToolStripControlHost类代码示例发布时间:2022-05-26
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap