By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,341 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,341 IT Pros & Developers. It's quick & easy.

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

pod
100+
P: 298
I work in MS Visual Studio 2008, I have a VB.NET Solution which has three Projects, BusinessObjectLibrary (object properties), DataAccessLibrary (object functions such as selectAll, exportToExcel) and WindowUserInterface (UserForms c/w Controls)


In my WindowUserInterface (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 "exportToExcel" and I have a Progress Bar called "rolProgressBar" ***.

In my DataAccessLibray (project) I have a class called "ROL_Adapter.vb", and in this class resides the function called "exportToExcel" 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 "exportToExcel" function.

How do I do this?

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

Can you help me?

I hope my explanation is good enough
Sep 8 '10 #1

✓ answered by pod

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

May this post save time to others

Share this Question
Share on Google+
3 Replies


Aimee Bailey
Expert 100+
P: 197
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.
Sep 8 '10 #2

pod
100+
P: 298
pod
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

Expand|Select|Wrap|Line Numbers
  1. Form_myForm1.Label1.Caption = "this is my label"
  2.  
As soon as I type "Form_myForm1" 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_Adapter"

I suppose I must Import or Reference something but I do not know what...
Sep 9 '10 #3

pod
100+
P: 298
pod
found my answer. It was a matter of adding a System.Windows.Forms reference to the "DataAccessLibrary" Project and to change the Access Modifier of the ProgressBar to "Public"

May this post save time to others
Sep 13 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.