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 October 25th, 2007, 02:09 PM
Authorized User
 
Join Date: Feb 2007
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to Access Control on a From from different cla

Hi All,

I have a Form in and a class, I need to access a control on Form1 from a other class. So i can populate the data in those control using other class. Please Help! if possibile please show some code.

I.e--> //Both classes in same project


class Form1
{

//All control in this class
ListBox list1 = new ListBox();
TextBox box1 = new TextBox();


}

class myClass
{

//Need to access a control of Form1 and fill with data, lets say we want fill list1 and set bo1.Text =

}


__________________
A.Asif
 
Old October 25th, 2007, 02:13 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Why don't you expose a public property on Form1 that will allow you to access the data then trying to access the controls?

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old October 27th, 2007, 05:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear friend there is 2 way but I guess u forgot something:
U cant use them in body of class I mean like this

Code:
class myClass
{
    bo1.Text = ...
}
& inorder to access them u shoul duse them in Methods of class like:
Code:
class myClass
{
    public myClass()
{
bo1.Text = ...
}}
[u]& thoes 2 ways</u>
1.
Code:
    class Form1
    {
        //All control in this class
        public ListBox list1 = new ListBox();
        public TextBox box1 = new TextBox();
    }


Code:
    class MyClass
    {
        public MyClass()
        {
            Form1 F1 = new Form1();
            Form1.box1 = 1;
        }
    }


2.
Code:
    static class Form1
    {
        //All control in this class
        public static ListBox list1 = new ListBox();
        public static TextBox box1 = new TextBox();
    }


Code:
        public MyClass()
        {
            Form1.box1 = ...;
        }


Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Access control from usercontrol peter2004 ASP.NET 1.x and 2.0 Application Design 10 January 28th, 2010 11:00 PM
401.3 Access denied due to Access Control List cforsyth .NET Framework 2.0 8 May 28th, 2009 01:56 PM
TemplateField control access cmw231 ASP.NET 2.0 Basics 0 July 11th, 2006 08:50 AM
Access the dynamic control using C# kapi.goel C# 19 February 2nd, 2006 07:21 AM





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