Static Public Void Function -- Cannot reference textBox.text

Posted on 2004-11-16
Last Modified: 2012-05-05
I have a form that is separate from the main form and I want to have a public function within that form that will refresh all of the textBox elements on the form.

However when I try to put textBox1.text = newValue in the static public function, the textBox1 element is an error how can i reference the local elements from a public form?
Question by:Rowdyone52
    LVL 1

    Expert Comment

    The problem is the static delaration of the function.  If you are going to have an instance of the form then it does not necessarily have to be static.

    What you could try is sending an event to the form instead of calling the public method such as from the main form:

    Or you could create an event on your main and listen for the event in your other form.
    LVL 3

    Expert Comment


    I dont get exactly what your problem is.

    But i think you are not able to access a textbox in form1, within a function in form1.
    If that is the problem,

    Then i think, you are not able to access textbox because your function is a static public function.
    Static public function can only access static variables.
    So, if your textbox is static, then only u will be able to use the textbox in your static public function.

    Hope this will be useful.
    Good luck.
    LVL 20

    Expert Comment

    Just remove the "static" part of the function declaration. Then call it like this: form.MyFunc();

    Author Comment

    If static isnt in the declaration, the Function doesnt show up as a available function.

    LVL 1

    Accepted Solution

    Are you calling the child form from the "Main" function?  Static methods may only call other static methods.  You may call the child form form the main form in the main form's load event.
    LVL 3

    Expert Comment

    HI Rowdy,

    Suppose u have a class called a.cs
    In which you have a function called yourFunction() like this,

    public void yourFunction()
    // do ur work

    Then wherever you want to use the function, first of all create an object of class a, like this,
    a myObject = new a();
    and then call,

    Hope this will be useful.
    Good luck.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    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.
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    737 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

    22 Experts available now in Live!

    Get 1:1 Help Now