?
Solved

How to access to Application windows controls ?

Posted on 2006-07-08
1
Medium Priority
?
244 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 1500 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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