Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old September 9th, 2007, 04:23 AM
Friend of Wrox
 
Join Date: Dec 2006
Location: , , .
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?
  #2 (permalink)  
Old September 9th, 2007, 10:35 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
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
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 09:34 AM.


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