How do you access the forms child objects from a different class?
-
I'm trying to access my forms (Form1) child objects, such as panels, sliderbars, toolbars, etc from a second class that i've added to the project. Currently i'm accessing Form1 via
Form1.ActiveForm
the problem that i'm having is that i can access the standard stuff from the form class, but nothing else, is this because Form1 is a public class, and all the child objects are private? if this is the case is it safe for me to change only the objects that i need to access to public, or is that unsafe coding? Is there a better way? or am i just going about this all wrong? :-D :laugh: ;p :^) :sigh: -
I'm trying to access my forms (Form1) child objects, such as panels, sliderbars, toolbars, etc from a second class that i've added to the project. Currently i'm accessing Form1 via
Form1.ActiveForm
the problem that i'm having is that i can access the standard stuff from the form class, but nothing else, is this because Form1 is a public class, and all the child objects are private? if this is the case is it safe for me to change only the objects that i need to access to public, or is that unsafe coding? Is there a better way? or am i just going about this all wrong? :-D :laugh: ;p :^) :sigh:Is it safe? Yeah. Is it proper coding practice? No way! Your second class shouldn't know anything about the form that called it. Your Form should be passing the data it needs to to the class methods and processing any return data required. Your second class should not be trying to modify the form, or read from it, at all. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
I'm trying to access my forms (Form1) child objects, such as panels, sliderbars, toolbars, etc from a second class that i've added to the project. Currently i'm accessing Form1 via
Form1.ActiveForm
the problem that i'm having is that i can access the standard stuff from the form class, but nothing else, is this because Form1 is a public class, and all the child objects are private? if this is the case is it safe for me to change only the objects that i need to access to public, or is that unsafe coding? Is there a better way? or am i just going about this all wrong? :-D :laugh: ;p :^) :sigh:JstDaNuGuy wrote:
if this is the case is it safe for me to change only the objects that i need to access to public, or is that unsafe coding?
You should not make any field in a class public. See this article on Why make fields in a class private, why not make them public?[^]
JstDaNuGuy wrote:
Is there a better way?
Yes. But it depends on what you are trying to do. What is the purpose of the second class? And what is the reason for the interaction? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
-
JstDaNuGuy wrote:
if this is the case is it safe for me to change only the objects that i need to access to public, or is that unsafe coding?
You should not make any field in a class public. See this article on Why make fields in a class private, why not make them public?[^]
JstDaNuGuy wrote:
Is there a better way?
Yes. But it depends on what you are trying to do. What is the purpose of the second class? And what is the reason for the interaction? ColinMackay.net "Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius "If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
thanks for the information guys... what im' trying to do is set the form state upon load then save on exit. but i have much more to set/save than just the form size, and i was just trying to do it from a different class i'm still learning... :-D :laugh: ;p :^) :sigh: