Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2007, 04:23 AM
Friend of Wrox
 
Join Date: Dec 2006
Posts: 176
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
 
Old September 9th, 2007, 10:35 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Theme/skin win forms controls planoie .NET Framework 2.0 3 August 21st, 2008 04:28 PM
Activate or Deactivate controls on forms chacquard Access VBA 3 November 27th, 2006 08:03 AM
Let user make forms and controls smang VB.NET 2002/2003 Basics 0 September 2nd, 2005 04:06 PM
Can Forms/controls be accessed remotely wizbang Pro VB 6 0 November 11th, 2004 07:46 PM





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