How do I access a WindowForm element from a Class function?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pod
    Contributor
    • Sep 2007
    • 298

    How do I access a WindowForm element from a Class function?

    I work in MS Visual Studio 2008, I have a VB.NET Solution which has three Projects, BusinessObjectL ibrary (object properties), DataAccessLibra ry (object functions such as selectAll, exportToExcel) and WindowUserInter face (UserForms c/w Controls)


    In my WindowUserInter face (project) I have a form called "rolFormGrid.vb ", on this form, I have a DataGrid that gets filled with a function called "selectAll" when the form is loaded, I also have a button that calls the function "exportToEx cel" and I have a Progress Bar called "rolProgressBar " ***.

    In my DataAccessLibra y (project) I have a class called "ROL_Adapter.vb ", and in this class resides the function called "exportToEx cel" which has all the code to create an Excel Workbook. When this function is being called, it can takes close to a minute to export to excel. We all know how users can be impatient if they do not see anything happening in the foreground when an application is working, that is the reason I want the progress bar.

    I want to access this progressbar from my code in my "exportToEx cel" function.

    How do I do this?

    In MS Access I would call Form_FormName.P rogressBar but I cannot find the way in VB.NET to address the Form

    Can you help me?

    I hope my explanation is good enough
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    The easiest way to do this would be to use events, have a set of events on the class that is executing code that raises an event when something happens, and have your form listen for it. when the event is fired, the form can respond by updating the progress bar.

    Hope this helps

    Aimee.

    Comment

    • pod
      Contributor
      • Sep 2007
      • 298

      #3
      I need to clarify a bit more

      thanks Aimee for taking a peek at my problem.
      I need to clarify a bit more my problem, the best way I can think of is by comparison with MS Access development in VBA. I hope you are familiar with this.

      When developing in VBA we have MS Office Access Class Objects and Modules.

      I tend to put all of my functions in modules. In my functions, if I want to change a caption on a form, I can address the form this way

      Code:
      Form_myForm1.Label1.Caption = "this is my label"
      As soon as I type "Form_myFor m1" and put a dot, all of my form elements appear in context.

      On my VB.NET I can address the form element from the form code side just by typing "Me." but I am unable to do this in my function which is in project "ROL_Adapte r"

      I suppose I must Import or Reference something but I do not know what...

      Comment

      • pod
        Contributor
        • Sep 2007
        • 298

        #4
        found my answer. It was a matter of adding a System.Windows. Forms reference to the "DataAccessLibr ary" Project and to change the Access Modifier of the ProgressBar to "Public"

        May this post save time to others

        Comment

        Working...