[RESOLVED] Progress bar on different form
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: [RESOLVED] Progress bar on different form

  1. #1
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    110

    [RESOLVED] Progress bar on different form

    Hi, I'm having a very hard time setting up my forms so that I can modify a progress bar on one form from within it's parent load method. I'm using VS 2010 and .NET Framework 4.0

    The Main form is opened, and from it's load method I open a Splash screen. I want it to have a progress bar that will be updated according to the Main forms loading progress.

    I tried adding a public method UpdateProgress() to the splash, but I don't see the method from the main form.
    Code:
    public void UpdateProgress()
    {
    	LoadProgress.PerformStep();
    }
    --> Splash.UpdateProgress() does not exist

    I tried adding an event so that I can update the progress raising events, but then again to do so I need to add a subscription method I can't see.
    Code:
    // On MainGUI form class:
    public event ProgressHandler Progress;
    public EventArgs e = null;
    public delegate void ProgressHandler(MainGUI m, EventArgs e);
    Code:
    // On Splash form class:
    public void Subscribe(MainGUI m)
    {
    	m.Progress += new MainGUI.ProgressHandler(UpdateProgress);
    }
    
    private void UpdateProgress(MainGUI m, EventArgs e)
    {
    	LoadProgress.PerformStep();
    }
    --> Splash.Subscribe(m) does not exist

    I tried modifying the controls visibility to internal or public, but I don't see it from the main form.
    --> Splash.LoadProgress does not exist

    How can I track the form's loading progress on the other form? Can it really be that difficult???

    Thanks in advance for any help! Cheers!

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,851

    Re: Progress bar on different form

    Where is the code that actually loads the splash form?
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    110

    Re: Progress bar on different form

    That would be:

    Code:
    private void MainGUI_Load(object sender, EventArgs e)
    {
    	Form Splash = new Forms.Splash();
    	//Splash.Subscribe(this);
    	Splash.Show();
    	
    	// Progress(this, e);
    
    	...
    
    	//while (Splash.Visible) { Application.DoEvents(); } // Wait for Splash screen to clear.
    }
    "Forms" is a Folder in my project where all the forms are grouped.

    Nothing to do with what I'm asking, but just out of curiosity:
    The last 'while' was intended to just show the splash for a few seconds and clear it after a timer timeout (or click, or keyup) event. Terrible way to do that, probably... any better suggestions?

    Thanks!

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Progress bar on different form

    Looks to me like you are trying to call instance methods as if they were static:

    Code:
    Splash.UpdateProgress() does not exist
    Yet

    Code:
    Splash s = new Splash();
    s.UpdateProgress();  // works fine

  5. #5
    Join Date
    Jun 2011
    Location
    Buenos Aires, Argentina
    Posts
    110

    Re: Progress bar on different form

    Well, not sure if you meant what I just fixed, but the problem was that Splash was being declared as a generic "Form" object and not a Splash:Form object
    Code:
    	Form Splash = new Forms.Splash();
    as oposed to
    Code:
    	Forms.Splash Splash = new Forms.Splash();
    Since "Splash" is actually a form, it was not even warning'd. I guess I was looking at the problem from the wrong point of view =)

    Thank you BigEd! Problem solved...

  6. #6
    Join Date
    Feb 2011
    Location
    United States
    Posts
    1,006

    Re: [RESOLVED] Progress bar on different form

    Part of the confusion stems from the odd coding style you are using. In general, variables use camelCase while classes are written in PascalCase (thus your use of uppercase-starting "Splash" for your variable name led to confusion -- we thought you were talking about the class). It will make it easier for you to communicate with other programmers if you follow standard conventions.

    See, for example: http://blogs.msdn.com/b/brada/archiv...26/361363.aspx

    Especially section 2.6 on Naming.
    Best Regards,

    BioPhysEngr
    http://blog.biophysengr.net
    --
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center