-
[RESOLVED] SplashScreen with ProgressBar
Hi!!!
I have a "main" form named MuShop and I have another form called Entrada (The SplashScreen form) in this form i've a progressbar.
In MuShop Load event i'v this lines of code
VB Code:
Me.Hide()
Entrada.ApplicationTitle.Text = My.Application.Info.Title
Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Entrada.Copyright.Text = My.Application.Info.Copyright
Entrada.Show()
ByItem_()
Search_()
Entrada.Close()
Me.Show()
In ByItem and in Search subs i'v loops and other code that increase the progressbar value(from Entrada).
With this code the the progressbar reachs the value 100 but the textboxs are not showned correcty they stay like "invisible" (i can beyond the form). So i tried a diffenrent code:
VB Code:
Me.Hide()
Entrada.ApplicationTitle.Text = My.Application.Info.Title
Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Entrada.Copyright.Text = My.Application.Info.Copyright
Entrada.ShowDialog()
Me.Dispose()
ByItem_()
Search_()
Entrada.Close()
Me.Show()
With this code the textboxes stay fine but the progressbar stays like inactive as it wans't get orders althougth they are there.
So anyone know a way to solve this?
-
Re: SplashScreen with ProgressBar
If it's not necessary to hide the main form then show Entrada form as modelly using
<objEntrada>.ShowDialog()
and if it's necessay to hide main form then simply run
ByItem_()
Search_()
In different thread ( u can use BackgroundWorker). but to show progress u need an Inter-Thread communication .. This can be done by delegate.
Lots of thread of delegate and backgroudworker is available in forum.
-
Re: SplashScreen with ProgressBar
Cross-threading :) I love it
-
Re: SplashScreen with ProgressBar
Hi!!!
I tried to look in forum for delegate and i'v being reding many threads but i still can figure it how can i make progressbar working and the form to be show correctly.
Can anyone help me here?
-
Re: SplashScreen with ProgressBar
Heres an example:
VB Code:
Delegate Sub dlgSetInteger(ByVal value As Integer)
Private Sub SetProgressBar1Value(ByVal value As Integer)
If Me.ProgressBar1.InvokeRequired Then
Me.ProgressBar1.Invoke(New dlgSetInteger(AddressOf SetProgressBar1Value), New Object() {value})
Else
Me.ProgressBar1.Value = value
End If
End Sub
And now, instead of using:
to set a value, write like this:
VB Code:
SetProgressBar1Value(100)
-
Re: SplashScreen with ProgressBar
It dont work I put like this:
In MainForm (MuShop):
Delegate Sub dlgSetInteger(ByVal value As Integer)
Private Sub SetProgressBar1Value(ByVal value As Integer)
If Entrada.Principal.InvokeRequired Then
Entrada.Principal.Invoke(New dlgSetInteger(AddressOf SetProgressBar1Value), New Object() {value})
Else
Entrada.Principal.Value = value
End If
End Sub
In Search_():
SetProgressBar1Value(10)
In MainForm Load:
Entrada.ShowDialog()
ByItem_()
Search_()
Entrada.Close()
Me.Show()
Why doesnt work??!?
-
Re: SplashScreen with ProgressBar
-
Re: SplashScreen with ProgressBar
No But the ProgressBar (Principal) from Entrada doenst "move".
I'v notice another curious thing if i put this code:
Entrada.ApplicationTitle.Text = My.Application.Info.Title
Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Entrada.Copyright.Text = My.Application.Info.Copyright
Entrada.ShowDialog()
The ApplicationTitle.text, Version.text ... stays good but if i put this code:
Entrada.ShowDialog()
Entrada.ApplicationTitle.Text = My.Application.Info.Title
Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Entrada.Copyright.Text = My.Application.Info.Copyright
The ApplicationTitle.Text ... doens show the correct text. Why?
-
Re: SplashScreen with ProgressBar
You need to replace:
with:
Because the lines underneath will not be executed unless entreda is closed, when you use showdialog.
When using ShowDialog, the form behaves as a dialog, i.e it "pauses" your application until it has been closed.
-
Re: SplashScreen with ProgressBar
Ok i get a way of the code:
Entrada.ApplicationTitle.Text = My.Application.Info.Title
Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
Entrada.Copyright.Text = My.Application.Info.Copyright
desapear but now when i put Entrada.show() the progressbar freezes and dont move. And if i put Entrada.Showdialog() the progressbar moves but the labels stay like transparents
How can i have the progressbar and the labels working good?
-
Re: SplashScreen with ProgressBar
wrap your code in a try statement
Like this:
VB Code:
Try
'Put your code here
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
And let's see what it says.
-
1 Attachment(s)
Re: SplashScreen with ProgressBar
Ok, I think u need a real demo.. Here i am attaching a sample..
it is without try catch block .. So, just look at the funda..
Enjoy
-
Re: SplashScreen with ProgressBar
Hi!!!
Lool it doesn't say nothing.
I put the code in MainForm Load event like this:
Entrada.ShowDialog()
Try
ByItem_()
Search_()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Entrada.Close()
Me.Show()
and no results so i tried this
Try
Entrada.ShowDialog()
ByItem_()
Search_()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Entrada.Close()
Me.Show()
Again no results. No MessageBox the progressbar dont move but the labels good.
Any more ideias?
-
Re: SplashScreen with ProgressBar
Have u looked at the example i attached in the previous thread ...
Call
ByItem_()
Search_()
methods in BackgroundWorker1_DoWork event.. What u need to look at is SetHeader Method , update code to change the value of progressbar rather to change the Form's Text property.
-
Re: SplashScreen with ProgressBar
Let me explain all again!!
I've to forms MuShop, the mainform and Entrada, the splashscreen.
In Entrada i'v none code its empty it has only the labels and the progressbar called Principal.
In MuShop i've a Load Event that calls the Sub Search_() and Sub ByItem_().
In Search_() Sub and in ByItem_() Sub i've this line of code Entrada.Principal.Value=Entrada.Principal.Value+10.
What i want is:
1)When the program starts shows Entrada form (the splash screen)
2)The Principal (Progressbar) "moves", but for that the program will have to go to Search_() and ByItem_()
3)While the Principal moves the labels in Entrada are shown correctly
4)When the Principal.value=100 (When he finishs to read Search_() and ByItem_() the Principal.value is 100) he closes Entrada and returns to MuShop.
Was i clear? If not pls tell me!!!
Ops while i has editing this post u give the example lool
-
Re: SplashScreen with ProgressBar
Just download attachment i uploaded in 12th post of this Thread..
Anyway code with slight modification is as below..
Form1 is main Class
Form2 is class having ProgressBar
VB Code:
Public Class Form1
Private counter As Integer = 0
Private Delegate Sub HideShowFormDelegate()
Private Delegate Sub SetHeaderDelegate(ByVal val As Integer)
Public Sub SetHeader(ByVal val As Integer)
If Me.InvokeRequired Then
Me.Invoke(New SetHeaderDelegate(AddressOf SetHeader), val)
Else
counter += val
BackgroundWorkerExample.Form2.ProgressBar1.Value = counter 'BackgroundWorkerExample is project name --> in 2005 u can use this
End If
End Sub
Public Sub HideForm()
If Me.InvokeRequired Then
Me.Invoke(New HideShowFormDelegate(AddressOf HideForm))
Else
Me.Hide()
End If
End Sub
Public Sub ShowForm()
If Me.InvokeRequired Then
Me.Invoke(New HideShowFormDelegate(AddressOf ShowForm))
Else
BackgroundWorkerExample.Form2.Close()
Me.Show()
End If
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
Call HideForm()
Dim varloop As Integer = 0
While varloop <= 3
varloop += 1
Threading.Thread.Sleep(1000)
Call SetHeader(varloop)
End While
Call ShowForm()
BackgroundWorker1.CancelAsync()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BackgroundWorkerExample.Form2.Show()
BackgroundWorker1.WorkerSupportsCancellation = True
BackgroundWorker1.RunWorkerAsync()
End Sub
End Class
-
Re: SplashScreen with ProgressBar
Ok i downloaded the example. Its good but the form2 when the form1 back to the "scene" doesn't desapear!
-
Re: SplashScreen with ProgressBar
Hum,
VB Code:
Public Sub ShowForm()
If Me.InvokeRequired Then
Me.Invoke(New HideShowFormDelegate(AddressOf ShowForm))
Else
BackgroundWorkerExample.Form2.Close() ' Add this one
Me.Show()
End If
End Sub
Btw, When next time when u add Vb code then put it inside VBCODE tags
-
Re: SplashScreen with ProgressBar
Ok it worked!!! But ins't there a easy way to do this (if not i will use coool code, but i like a second opinion)
-
Re: SplashScreen with ProgressBar
I think one day u will going to use this one then why not today .. however, If u really want some another way this is as under..
When u want to hide main form and show Form2 .. just resize main form make it smaller than Form2, set it's location beside Form2 such that user can't watch it. ;)
Change main form's location in Form2's move event .. or make Form2 Dialog and border with Fixed Size..
ReSet main form's size after closing Form2..
HOWEVER, This should only be the LAST SOLUTION if can't SOLVE IT.
-
Re: SplashScreen with ProgressBar
Thks Coool for the ideia but i think i came with a better one! For curious people here it goes:
In Form1 Load event i just put this Frm2.ShowDialog()
In Form2 load event i put this Timer1.Start() (Timer interval = 100)
Then in Timer1_Tick event i put this code:
Timer1.Stop()
Call Subs (In my case Search_() and ByItem_() )
Me.Close
In Subs Search_() and ByItem_() i put lines like this one:
ProgressBar1.Value=ProgressBar1.Value +10 (In my case ProgressBar name is Principal)
-
Re: [RESOLVED] SplashScreen with ProgressBar
your problem is a matter of organizing subroutines. Just try to copy (not just call them) the ByItem_() and the other subroutine in the splash form itself and not in the MuShop form if this is possible and let these routines change the value of the prgress bar from the same form. Good???
-
Re: [RESOLVED] SplashScreen with ProgressBar
aloreefy .. I don't think ur idea will work fine looking at the use of Splash From .. because nce u call the subroutine on the Splash form .. it will freeze Splash Form till the completion of subroutine.. Any event like form click won't work until the process completion .. so u better to run the process that takes long time to complete on another thread.. This is the funda.
-
Re: [RESOLVED] SplashScreen with ProgressBar
What I meant Mr.Coool is to let the Splash form do something for you. Those long-time processes who run in the By_Iem and Search_() subroutines are called only once during the whole run of the program, surely, because they both affect the progress bar in the Splash form which appears only once at the start of the program (this is the normal case of any program). So why don't make the splash form do something for you??
-
Re: [RESOLVED] SplashScreen with ProgressBar
Ok ... As u wish, but for just once, put one button on SplashScreen Form and click it while this two methods are running .. u will come to know what i m trying to say ..
AND TELL ME IF UR CLICK RAISE ERROR OR UR PROGRAM SEEMS TO FREEZE..
-
Re: [RESOLVED] SplashScreen with ProgressBar
Dear Coool
Why put any button on a Splash screen, I mean, this is just a splash screen, an introductory form that just shows to the user till the program finishes all necessary steps while loading. So, let the splash screen finalize these steps and show the steps progress on its own progress bar.
Thanks