TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
andy mcinnes
NA
22
27.6k
Accessing form control from another class
Apr 18 2012 7:14 AM
Hi,
I am still rather newb with c# and I am just going through the painful task of translating my apps from vb.net to c#.net so I can integrate them all in to one easy to use app.
The problem I have never had before but seem to be having is accessing form controls from my classes.
I try to use a structure where by all database calls are in one class, all validation and calculations are in another class and then only the form controls are on the form code.
So an example of an issue I am having is that I read textbox values from the form and also do things like update the status strip progress bar etc.
I have even tried both with and without delegates and I simply can't manage it.
Usually if I want to access a form control I would reference a new form instance:
Form1 frm = new Form1();
and use it like this:
frm1.
ToolStripProgressBar1.Value = 100;
If I do this on the form it works fine:
this.
ToolStripProgressBar1.Value = 100;
But from another class just doesn't seem to work.
My guess is that I reference "= new Form1();"
Does this refer to a new instance of the form I am trying to access controls on and if so how do I access the current instance of a form?
I had been reading a little about IEnumerable<control> but I'm not sure if this is the right direction to go or how to implement it exactly?
Thanks in advance for any help!
Andy
Reply
Answers (
9
)
How to count condition datagrid?
Please tell me how to send parameters using threads from one page to another...