p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   C# 2005 (http://p2p.wrox.com/forumdisplay.php?f=138)
-   -   access other Forms Controls (http://p2p.wrox.com/showthread.php?t=61888)

angelboy September 9th, 2007 04:23 AM

access other Forms Controls
 
what's your idea on flowing code ?

Form1.Contrlos["button1"].Text="some text";

when this code used on Form2 for access the button1 on Form1

is it type safe code?
is it the opposite to OOP programming and encapsulation rules?

planoie September 9th, 2007 10:35 AM

Generally all .NET code is type safe as that is a feature of the framework (until you venture into unsafe code development).

You would better satisfy the encapsulation principle by exposing your button text property as a propety on the form. That way the calling code doesn't need to know about the controls itself, and you could also change what is encapsulated without breaking callers.

Put a property like this in Form1:

public string ButtonText{
   get{ return button1.Text; }
   set{ button1.Text = value; }
}

-Peter


All times are GMT -4. The time now is 04:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.