[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 251
  • Last Modified:

Static Public Void Function -- Cannot reference textBox.text

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?
0
Rowdyone52
Asked:
Rowdyone52
1 Solution
 
sendmeblahCommented:
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:
frmNotTheMainForm.Refresh()

Or you could create an event on your main and listen for the event in your other form.
0
 
chintan_vaishyaCommented:
Hi,

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.
Chintan.
0
 
TheAvengerCommented:
Just remove the "static" part of the function declaration. Then call it like this: form.MyFunc();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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

0
 
sendmeblahCommented:
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.
0
 
chintan_vaishyaCommented:
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,
myObject.yourFunction();

Hope this will be useful.
Good luck.
Chintan.
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now