Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calling form functions from Class 1

Status
Not open for further replies.

stillinlife101

Programmer
Feb 15, 2005
29
US
I have the function

public void FormLine(Point pt1, Point pt2) {}

that is declared in my main form. I want to call the function (i.e. in another class type frmMain.FormLine(params)) from another class, but it doesn't show up. How do I access those functions without making another instance of the form? It's not enough to make it static, it has to refer to the original instance of the form.

Thanks,

Dan
 
How are you declaring the variable of type frmMain? If you declare it as a Form, and not a frmMain, you'll never see your public methods/properties.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Thanks, I fixed it by passing a reference to the form to the function. It's the name form, so it's declared as an application, whatever that means.

Dan
 
Thanks, I fixed it by passing a reference to the form to the function. It's the name form, so it's declared as an application, whatever that means.

That'll probably work.

Just also wanted to make sure you're not coming from a VB background, where there was an implicit variable created behind the scenes for each form. In .net, that doesn't happen, as forms are objects, and they obey all the object variable rules. It's as if you were saying
Code:
Textbox.Text = "somevalue";
when you should have been using an instance of Textbox. Common error.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top