Solved

How to access to Application windows controls ?

Posted on 2006-07-08
1
235 Views
Last Modified: 2010-04-16
Hi experts,

how to access the main appclication form  controls ?

I don't like it doing it in the way below:
       
class newObject
{  
        private control xy;

        public newObject(MainApplicationForm application)
        {
            this.xy = application.control;
        }
}

Is there another chance to access to the controls ?
0
Comment
Question by:martinmoessner
1 Comment
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 17064732
If you want to access controls from any place from the program, expose them as properties from main form class. Make public static property with form reference and access controls using it.

class MainAplicationForm
{
    public TextBox TextBox1
    {
           return this.textBox1;
    }
    // ... add property for every control you want to expose

    static MainAplicationForm mainAplicationForm;

    public static MainAplicationForm MainForm
    {
          return mainAplicationForm;
    }

    public MainAplicationForm()
    {
        mainAplicationForm = this;
    }
}

To access textBox1 from any place of the program, assuming that main form is already created and there is only one instance of it:

MainAplicationForm.MainForm.TextBox1.Text = "...";
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now