Results 1 to 26 of 26

Thread: [RESOLVED] SplashScreen with ProgressBar

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [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:
    1. Me.Hide()
    2. Entrada.ApplicationTitle.Text = My.Application.Info.Title
    3. Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
    4. Entrada.Copyright.Text = My.Application.Info.Copyright
    5. Entrada.Show()
    6. ByItem_()
    7. Search_()
    8. Entrada.Close()
    9. 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:
    1. Me.Hide()
    2. Entrada.ApplicationTitle.Text = My.Application.Info.Title
    3. Entrada.Version.Text = System.String.Format(Entrada.Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor)
    4. Entrada.Copyright.Text = My.Application.Info.Copyright
    5. Entrada.ShowDialog()
    6. Me.Dispose()
    7. ByItem_()
    8. Search_()
    9. Entrada.Close()
    10. 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?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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.
    I am using .NET 2010 with Windows 7

  3. #3
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SplashScreen with ProgressBar

    Cross-threading I love it
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  5. #5
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SplashScreen with ProgressBar

    Heres an example:
    VB Code:
    1. Delegate Sub dlgSetInteger(ByVal value As Integer)
    2.  
    3.     Private Sub SetProgressBar1Value(ByVal value As Integer)
    4.         If Me.ProgressBar1.InvokeRequired Then
    5.             Me.ProgressBar1.Invoke(New dlgSetInteger(AddressOf SetProgressBar1Value), New Object() {value})
    6.         Else
    7.             Me.ProgressBar1.Value = value
    8.         End If
    9.     End Sub

    And now, instead of using:
    VB Code:
    1. ProgressBar1.Value = 100
    to set a value, write like this:
    VB Code:
    1. SetProgressBar1Value(100)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  6. #6

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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??!?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SplashScreen with ProgressBar

    Do you get any errors?
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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?
    Last edited by Lasering; Jun 10th, 2006 at 10:01 AM.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SplashScreen with ProgressBar

    You need to replace:

    VB Code:
    1. Entrada.ShowDialog()

    with:

    VB Code:
    1. Entrada.Show()

    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.
    Last edited by Atheist; Jun 10th, 2006 at 10:07 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  11. #11
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: SplashScreen with ProgressBar

    wrap your code in a try statement

    Like this:

    VB Code:
    1. Try
    2.             'Put your code here
    3.         Catch ex As Exception
    4.             MessageBox.Show(ex.Message)
    5.         End Try

    And let's see what it says.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  12. #12
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Wink 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
    Attached Files Attached Files
    I am using .NET 2010 with Windows 7

  13. #13

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  14. #14
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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.
    I am using .NET 2010 with Windows 7

  15. #15

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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
    Last edited by Lasering; Jun 10th, 2006 at 11:57 AM.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  16. #16
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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:
    1. Public Class Form1
    2.     Private counter As Integer = 0
    3.     Private Delegate Sub HideShowFormDelegate()
    4.     Private Delegate Sub SetHeaderDelegate(ByVal val As Integer)
    5.  
    6.     Public Sub SetHeader(ByVal val As Integer)
    7.         If Me.InvokeRequired Then
    8.             Me.Invoke(New SetHeaderDelegate(AddressOf SetHeader), val)
    9.         Else
    10.             counter += val
    11.             BackgroundWorkerExample.Form2.ProgressBar1.Value = counter 'BackgroundWorkerExample is project name --> in 2005 u can use this
    12.         End If
    13.     End Sub
    14.  
    15.     Public Sub HideForm()
    16.         If Me.InvokeRequired Then
    17.             Me.Invoke(New HideShowFormDelegate(AddressOf HideForm))
    18.         Else
    19.             Me.Hide()
    20.         End If
    21.     End Sub
    22.  
    23.     Public Sub ShowForm()
    24.         If Me.InvokeRequired Then
    25.             Me.Invoke(New HideShowFormDelegate(AddressOf ShowForm))
    26.         Else
    27.             BackgroundWorkerExample.Form2.Close()
    28.             Me.Show()
    29.         End If
    30.     End Sub
    31.     Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
    32.         Call HideForm()
    33.         Dim varloop As Integer = 0
    34.         While varloop <= 3
    35.             varloop += 1
    36.             Threading.Thread.Sleep(1000)
    37.             Call SetHeader(varloop)
    38.         End While
    39.         Call ShowForm()
    40.         BackgroundWorker1.CancelAsync()
    41.     End Sub
    42.  
    43.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    44.         BackgroundWorkerExample.Form2.Show()
    45.         BackgroundWorker1.WorkerSupportsCancellation = True
    46.         BackgroundWorker1.RunWorkerAsync()
    47.     End Sub
    48. End Class
    I am using .NET 2010 with Windows 7

  17. #17

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: SplashScreen with ProgressBar

    Ok i downloaded the example. Its good but the form2 when the form1 back to the "scene" doesn't desapear!
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  18. #18
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    Re: SplashScreen with ProgressBar

    Hum,

    VB Code:
    1. Public Sub ShowForm()
    2.         If Me.InvokeRequired Then
    3.             Me.Invoke(New HideShowFormDelegate(AddressOf ShowForm))
    4.         Else
    5.             BackgroundWorkerExample.Form2.Close() ' Add this one
    6.             Me.Show()
    7.         End If
    8.     End Sub

    Btw, When next time when u add Vb code then put it inside VBCODE tags
    I am using .NET 2010 with Windows 7

  19. #19

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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)
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  20. #20
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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.
    I am using .NET 2010 with Windows 7

  21. #21

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    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)
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  22. #22
    New Member
    Join Date
    Jun 2006
    Posts
    4

    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???

  23. #23
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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.
    I am using .NET 2010 with Windows 7

  24. #24
    New Member
    Join Date
    Jun 2006
    Posts
    4

    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??

  25. #25
    Hyperactive Member Coool's Avatar
    Join Date
    Feb 2006
    Location
    System.Coool
    Posts
    333

    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..
    I am using .NET 2010 with Windows 7

  26. #26
    New Member
    Join Date
    Jun 2006
    Posts
    4

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width