Solved

How to access to Application windows controls ?

Posted on 2006-07-08
1
242 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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