RobertoFreemano
asked on
Add Progress bar to my Winform (VB.NET 2003)
Hi Experts,
I have a simple Winform with a Listbox & RichTextBox. The Listbox loads RTF files from DIR into Listbox names... If I click on ListboxItem... it loads contents of that file into the RichTextBox.
Because the RFT files are located on a server, some of the files are 11mb.... & this takes time to streamread it into the RichTextBox... I would like to know how to add a progress bar to show loading progress.
Thanks,
Rob
I have a simple Winform with a Listbox & RichTextBox. The Listbox loads RTF files from DIR into Listbox names... If I click on ListboxItem... it loads contents of that file into the RichTextBox.
Because the RFT files are located on a server, some of the files are 11mb.... & this takes time to streamread it into the RichTextBox... I would like to know how to add a progress bar to show loading progress.
Thanks,
Rob
Option Explicit On
Imports System.IO
Imports System.Threading
Imports System.Diagnostics
Public Class Form1
Inherits System.Windows.Forms.Form
Dim aDate As Date
Dim dateString As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadFiles()
Try
' folder exists
Dim path As String
Dim di As System.IO.DirectoryInfo
path = "\\server\share\folderA\"
di = New System.IO.DirectoryInfo(path)
If (Not di.Exists) Then
di.Create()
End If
Catch ex As Exception
MsgBox("Error code 22: The Dir doesn't exist!")
End Try
Label3.Text = ListBox1.Items.Count.ToString()
End Sub
Private Sub LoadFiles()
Try
Dim sourceFolder As String = "\\server\share\folderA\"
ListBox1.BeginUpdate()
ListBox1.Items.Clear()
ListBox1.Items.AddRange((New System.IO.DirectoryInfo(sourceFolder)).GetFiles("*.rtf"))
ListBox1.EndUpdate()
Catch ex As Exception
MsgBox("Error!")
End Try
End Sub
Private Sub LoadFiles()
Try
Dim sourceFolder As String = "\\server\share\folderA\"
ListBox1.BeginUpdate()
ListBox1.Items.Clear()
ListBox1.Items.AddRange((New System.IO.DirectoryInfo(sourceFolder)).GetFiles("*.rtf"))
ListBox1.EndUpdate()
Catch ex As Exception
MsgBox("Error code 45: The repository is empty!")
End Try
End Sub
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
dateString = aDate.Now.ToString("ddMMyyyy")
Try
If Not (ListBox1.SelectedItem Is Nothing) Then
RichTextBox1.Rtf = CType(ListBox1.SelectedItem, System.IO.FileInfo).OpenText.ReadToEnd
End If
Dim filename As String = IO.Path.GetFileNameWithoutExtension(ListBox1.Text)
Label1.Text = filename
Catch ex As Exception
MsgBox("Error!")
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To be able to show progress while reading a file, you need to read the file in chunks.
The other option is to use a Marquee type progressbar then you would have to load the file in a separate thread so that the UI thread can paint the progressbar.
The other option is to use a Marquee type progressbar then you would have to load the file in a separate thread so that the UI thread can paint the progressbar.
He's working in VB.Net 2003 so the BackgroundWorker and Marquee style ProgressBar are out... =\
Yeah but he can use threads and a custom progressbar.
@Idle_Mind,
Why do you say BackgroundWorker not an option for VS 2003? I use VS 2003 and the BackgroundWorker class.
Why do you say BackgroundWorker not an option for VS 2003? I use VS 2003 and the BackgroundWorker class.
...because it wasn't added until .Net 2.0 in VS2005:
http://msdn.microsoft.com/en-us/library/35f2fe4h.aspx
http://msdn.microsoft.com/en-us/library/t357fb32.aspx
Not sure what you're using in 2003?!...
http://msdn.microsoft.com/en-us/library/35f2fe4h.aspx
http://msdn.microsoft.com/en-us/library/t357fb32.aspx
Not sure what you're using in 2003?!...
ASKER
Zhaolai,
Your "Cursor.Current = Cursors.WaitCursor" seems to work for me...
Thanks ;)
Your "Cursor.Current = Cursors.WaitCursor" seems to work for me...
Thanks ;)
https://www.experts-exchange.com/questions/26569623/Progress-Bar-for-FTP-download-in-async.html