Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Making a generic progress form

Making a generic progress form

Scheduled Pinned Locked Moved C#
visual-studiohelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Etienne_123
    wrote on last edited by
    #1

    Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:

    public ProgressForm()
    {
    SomeUserControl._updateProgressbarDelegate =
    new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
    }

    This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that updateProgressbarDelegate is actually a delegate in the form/usercontrol I just passed through? If I do something like this:

    public ProgressForm(UserControl callingControl)
    {
    //do something with callingControl
    }

    ..then updateProgressbarDelegate will obviously not show up in intellisense when typing callingControl. because it doesn't know of what type callingControl is. Could anyone please provide some help or hints?

    R _ R 3 Replies Last reply
    0
    • E Etienne_123

      Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:

      public ProgressForm()
      {
      SomeUserControl._updateProgressbarDelegate =
      new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
      }

      This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that updateProgressbarDelegate is actually a delegate in the form/usercontrol I just passed through? If I do something like this:

      public ProgressForm(UserControl callingControl)
      {
      //do something with callingControl
      }

      ..then updateProgressbarDelegate will obviously not show up in intellisense when typing callingControl. because it doesn't know of what type callingControl is. Could anyone please provide some help or hints?

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      Hi, there are many solutions too this problem. In your situation I would ask the question why a delegate is needed at all. As I can see you have a UpdateProgress method in your form. Lets assume it is public, then a caller could do the following:

      ProgressForm pf = new ProgressForm();
      pf.Show();
      for (int i = 0; i < 10000; i++)
      {
      //do some work
      pf.UpdateProgress(i);
      }

      To seperate the worker and the form you could introduce an interface along with a factory but I think this would go a bit to far for a forum answer :). Also browse through atricle on this site related to your needs: http://www.codeproject.com/info/search.aspx?artkw=progress[^] Robert

      1 Reply Last reply
      0
      • E Etienne_123

        Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:

        public ProgressForm()
        {
        SomeUserControl._updateProgressbarDelegate =
        new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
        }

        This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that updateProgressbarDelegate is actually a delegate in the form/usercontrol I just passed through? If I do something like this:

        public ProgressForm(UserControl callingControl)
        {
        //do something with callingControl
        }

        ..then updateProgressbarDelegate will obviously not show up in intellisense when typing callingControl. because it doesn't know of what type callingControl is. Could anyone please provide some help or hints?

        _ Offline
        _ Offline
        _Erik_
        wrote on last edited by
        #3

        I wrote an article about this. Have a look[^]. It might help you.

        1 Reply Last reply
        0
        • E Etienne_123

          Hi I created a form that acts as a progress indicator, including a progressbar and some labels etc. In the constructor of the progress form I register the delegate on the form that calls the progress form like so:

          public ProgressForm()
          {
          SomeUserControl._updateProgressbarDelegate =
          new SomeUserControl.UpdateProgressbarDelegate(this.UpdateProgress);
          }

          This approach however needs to be made more generic so that it can be called from various other UserControls and forms. I`m not sure what the best aproach would be to do this. I tried passing the calling form/usercontrol through to the constructor when creating an instance of the progress form, but how would I then know that updateProgressbarDelegate is actually a delegate in the form/usercontrol I just passed through? If I do something like this:

          public ProgressForm(UserControl callingControl)
          {
          //do something with callingControl
          }

          ..then updateProgressbarDelegate will obviously not show up in intellisense when typing callingControl. because it doesn't know of what type callingControl is. Could anyone please provide some help or hints?

          R Offline
          R Offline
          RaviRanjanKr
          wrote on last edited by
          #4

          I found a very interesting link which guide you how to create a Generic Progress Dialog. go there[^]

          E 1 Reply Last reply
          0
          • R RaviRanjanKr

            I found a very interesting link which guide you how to create a Generic Progress Dialog. go there[^]

            E Offline
            E Offline
            Etienne_123
            wrote on last edited by
            #5

            Thanks for all the replies :) I managed to sort it out

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups