Solved

How to access to Application windows controls ?

Posted on 2006-07-08
1
236 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML & .net 5 41
In C#, how would you convert a byte array to its integer value equivalent? 12 38
Need help on C# Linq query on object 6 53
ASP.NET 5 Templates 2 66
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
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…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

11 Experts available now in Live!

Get 1:1 Help Now