CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    105

    Calling Form controls from Other classes

    Hi All,

    Here I have some problem. my main form become too bit, It has lot of controls, And one timer is running in it, for loading and performing some tasks it is taking time, For that I want to redesign(Reaggange) my application structure,
    "Mainly i want to move some controls code to different class", Is there any way of accessing Form controls from other class. Like

    class Class1
    {
    private string text="Hello";
    public void AccessFromControls()
    {
    button1.Text=text; //Like this
    }
    }

    Please provide some way to proceed.

    Regards
    Ravi

  2. #2
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: Calling Form controls from Other classes

    Before accessing the controls from a class, that class needs to know about the instance of the form. So you will need to have a way of letting your class know that there is form existing whose controls you want to access. This can be done by having a property where you can set which Form you are going to use and then you also need to make the controls in your form public.

  3. #3
    Join Date
    Nov 2004
    Posts
    105

    Re: Calling Form controls from Other classes

    Hi
    Thanks for the reply. I got it. I missed making the control as public.

    Regards
    Ravi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured