Accessing a control from a separate class
-
Hi at all, on my Windows Form i have some Controls whose properties need to be changed by another class that is not derived from the Forms class. How can this be achieved? (is it possible at all?) For example: public class Form : System.Windows.Forms.Form { ... public System.Windows.Forms.ToolStripStatusLabel tlStrpStatusLblState; ... } public class PB_OPC { public static void OnServerShutdown(string reason) { Form.tlStrpStatusLblState.Text = "OPC Server Not Connected"; } } I originally thought that would be possible by changing the "modifiers" Attribute to "Public", but it didn't help. Thanks for your efforts
-
Hi at all, on my Windows Form i have some Controls whose properties need to be changed by another class that is not derived from the Forms class. How can this be achieved? (is it possible at all?) For example: public class Form : System.Windows.Forms.Form { ... public System.Windows.Forms.ToolStripStatusLabel tlStrpStatusLblState; ... } public class PB_OPC { public static void OnServerShutdown(string reason) { Form.tlStrpStatusLblState.Text = "OPC Server Not Connected"; } } I originally thought that would be possible by changing the "modifiers" Attribute to "Public", but it didn't help. Thanks for your efforts
-
Hi, thanks a lot, it really did help, but i truly agree that this isn't the best solution. What about the programming style in OOP? Is it a bad habit to access a control from a separate class? I just wondered if there's an alternative.
Hello,
JF2015 wrote:
Is it a bad habit to access a control from a separate class?
Yes, it is! Couse in most cases you only need a property of this control! Look at this Article from Colin Angus Mackay: http://www.codeproject.com/dotnet/passingvaluesbetweenforms.asp[^] Hope it helps! All the best, Martin
-
Hello,
JF2015 wrote:
Is it a bad habit to access a control from a separate class?
Yes, it is! Couse in most cases you only need a property of this control! Look at this Article from Colin Angus Mackay: http://www.codeproject.com/dotnet/passingvaluesbetweenforms.asp[^] Hope it helps! All the best, Martin
Thanks for the link. :-D
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
Thanks for the link. :-D
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website
-
:laugh: Yes, I sure did. :cool:
Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website