Solved

How to access to Application windows controls ?

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

Title # Comments Views Activity
PrintingFoundIt(Almost!(Damn!)) 1 30
Firing an ASP.NET event on selection of a JQuery datepicker 4 30
VB.NET 2008 Winforms Signing 13 31
How to read text with RegEx... 2 25
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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