ProgressBar showing pourcentage - vb.net

I wanted to show the pourcentage within the ProgressBar but it shows 1% for one file spotted instead of showing 100%.
screenshot
I understand why it shows me 1% and I know I've to change Label1Text to another value but I don't see which one would solve the problem.
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Timer1.Start()
Dim dossier = "C:\Users\adm\Desktop\A"
Dim lesFichiers() As System.IO.FileInfo
Dim dirinfo As New System.IO.DirectoryInfo(dossier)
lesFichiers = dirinfo.GetFiles("*", IO.SearchOption.AllDirectories)
For Each chaqueFichier In lesFichiers
ProgressBar1.Maximum = lesFichiers.Length
ProgressBar1.Value += 1
Next
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
ProgressBar1.Increment(2)
label1.Text = ProgressBar1.Value & " %"
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
End If
End Sub
Private Sub Label1_Click(sender As System.Object, e As System.EventArgs)
Label1.BackColor = Color.Transparent
End Sub
Private Sub ProgressBar1_Click(sender As System.Object, e As System.EventArgs) Handles ProgressBar1.Click
End Sub
End Class

Related

How can I increase the font size of the user's input by one every 2 seconds in the code below?

Public Class Form1
Dim mypicturebox As New PictureBox
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = "hello " & TextBox1.Text
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
Me.Label1.Text = "enter your name"
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mypicturebox.BackColor = Color.Red
mypicturebox.Width = 50
mypicturebox.Height = 50
mypicturebox.Left = 100
mypicturebox.Top = 100
Me.Controls.Add(mypicturebox)
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim MyFont As New Font(TextBox1.Font.FontFamily, 12, FontStyle.Bold)
Dim size As Integer = 30
Me.Font = New Font(Me.Font.FontFamily, size)
Label1.Font = New Font(Label1.Font.FontFamily, size)
Label1.Font.Size = Label1.Font.Size + 1
End Sub
End Class
When I run the code, it says that the font size is read-only so I cannot change it.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 2000 '2 sec
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
TextBox1.Font = New Font(TextBox1.Font.FontFamily, TextBox1.Font.Size + 1)
End Sub

WebBrowser1.Navigate loop request

How can i make this code to loop urls continuously in Webbrowser1, after run trough these links one time.
This is the code i have so far, but when i run this, the Webbrowser stop with last url, wich is google.com. What i want to do is when the last url is reached i want it to start from top again, and run trough links again and again, until i exit the program.
Public Class Form1
Private WithEvents backgroundWorker1 As System.ComponentModel.BackgroundWorker
Dim l As New List(Of String)
Dim flagDC As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Hide()
Button3.Show()
l = New List(Of String)
l.Add("http://bbc.com/sipeu/php/zq.php")
l.Add("http://google.com")
l.Add("http://DCWC.com/sipeu/us.php")
l.Add("http://google.com")
l.Add("http://example.com/sipeu/v.php")
l.Add("http://google.com")
backgroundWorker1 = New System.ComponentModel.BackgroundWorker
backgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker2_DoWork(ByVal sender As System.Object,
ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles backgroundWorker1.DoWork
For Each www In l
flagDC = False
WebBrowser1.Navigate(www)
Do
Loop While Not flagDC
Next
End Sub
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) _
Handles WebBrowser1.DocumentCompleted
System.Threading.Thread.Sleep(1000)
flagDC = True
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Button3.Hide()
ChangeUserAgent("troll001_v2-agent34")
WebBrowser1.Navigate("http://example.com/welcome.php")
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
End Sub

Do Process while Progress Bar is Running

I know that knowledge is expensive, but is there who want to help me
i want to run process when progress bar is running,
i try with this code
Public Class Form2
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call Prcss()
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If Progress.Value < 100 Then
Progress.Value += 2
ElseIf Progress.Value = 100 Then
Timer1.Stop()
Form1.Show()
Me.Hide()
End If
End Sub
Private Sub Prcss()
With Progress
.Value = 0
Threading.Thread.Sleep(450)
Label1.Text = "Renewing Custom Content"
.Value = 20
Threading.Thread.Sleep(450)
Label1.Text = "Getting Information"
.Value = 50
Threading.Thread.Sleep(450)
Label1.Text = "Downloading Udpdate"
.Value = 70
Threading.Thread.Sleep(450)
Label1.Text = "Ready to Start"
.Value = 100
End With
End Sub
i don't know where is my mistake, i read this on my book.
Try using a BackgroundWorker or a Thread:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
BackgroundWorker1.RunWorkerAsync()
End Sub
Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
For i As Integer = 1 To 1000
BackgroundWorker1.ReportProgress(CInt(i / 10))
Threading.Thread.Sleep(500)
Next
End Sub
Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
ProgressBar1.Value = e.ProgressPercentage
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
MessageBox.Show("Finished!")
End Sub
This is the basic example and require you to add a BackgroundWorker to the form. You can see help here: https://msdn.microsoft.com/es-es/library/cc221403(v=vs.95).aspx

VB.net Form unexpectingly terminating

Hi I have the following form but cant figureout why its upbrubtly terminiating when difrent buttons are clicked?
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub button1_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
Dim TEST1 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST1 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
Private Sub button1_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub button2_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseLeave
Me.WebBrowser1.Navigate("http://WWW.facebook.com")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.WebBrowser1.Navigate("file://C:\test\test")
Button1.Enabled = False
Button2.Enabled = True
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.WebBrowser1.Navigate("file://C:\test")
Button2.Enabled = False
Button1.Enabled = True
End Sub
Private Sub button2_MouseEnter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.MouseEnter
Dim TEST2 As Integer = System.IO.Directory.GetFiles("C:\test\test").Length
If TEST2 = 0 Then
Me.WebBrowser1.Navigate("http://www.hotmail.com")
End If
End Sub
The terms face book and hotmail are just random to keep company site private :)
I suspect the Mouse_Enter event and the Mouse_Leave events are not giving time to the webbrowser to fully load the document and maybe it is internally crashing.
Try checking if the webbrowser has finished working before navigating again and tell us:
Use
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete
Me.WebBrowser1.Navigate("http://www.google.com")
End if

Multiple camera shots in vb

See I have this simple vb.net codes that counts from 5 to 1 then says capture! I need to do this 4 consecutive times after the start button is clicked .. I tried a do until loop but it didn't work, I'm a newbie here so please help..
Public Class Form_welcome
Dim Count As Integer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
Label2.Text = Count
If (Count = 0) Then
Timer1.Enabled = False
Label2.Hide()
Label3.Show()
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 5
Timer1.Enabled = True
Label2.Text = Count
Timer1.Interval = 1000
End Sub
End Class
something like this?
Public Class Form_welcome
Dim Count As Integer
Dim pictureCount as integer = 4
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
Label2.Text = Count
If (Count = 0) Then
pictureCount -=1
If pictureCount = 0 then
Timer1.Enabled = False
End If
'take a picture
Label2.Hide()
Label3.Show()
Count = 5
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 5
Timer1.Enabled = True
Label2.Text = Count
Timer1.Interval = 1000
End Sub
End Class
Public Class Form_welcome
Dim Count As Integer
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Admin_Login.Show()
Me.Hide()
End Sub
Private Sub Form_welcome_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Application.Exit()
End Sub
Private Sub Form_welcome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button4.Hide()
Button5.Hide()
Button6.Hide()
'Timer1.Enabled = True
'Label2.Text = Count
'Timer1.Interval = 1000
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Count -= 1
'Label2.Text = Count
If (Count = -1) Then
Timer1.Enabled = False
Label3.Show()
Label3.Hide()
Label2.Hide()
Button4.Show()
Button5.Show()
Button6.Show()
PictureBox4.Hide()
PictureBox3.Show()
pict1.Show()
pict2.Show()
pict3.Show()
pict4.Show()
Button2.Hide()
End If
If (Count Mod 3) = 0 Then
Label2.Text = "Captured!"
Else
Label2.Text = Count
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Count = 12
Timer1.Enabled = True
Label2.Text = Count
Label2.Show()
Timer1.Interval = 1000
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Application.Exit()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Button2.Show()
Button4.Hide()
Button5.Hide()
Button6.Hide()
PictureBox3.Hide()
pict1.Hide()
pict2.Hide()
pict3.Hide()
pict4.Hide()
PictureBox4.Show()
End Sub
End Class