Valhalla Legends Forums Archive | .NET Platform | [c#.net] working up the chain [solved]

AuthorMessageTime
mentalCo.
say i have a class named MyClass on my main form called Form1.  How do I call functions in Form1 from inside MyClass?

edit:

i solved it using events.
February 1, 2005, 11:52 PM
Myndfyr
[quote author=mentalCo. link=topic=10395.msg97830#msg97830 date=1107301945]
say i have a class named MyClass on my main form called Form1.  How do I call functions in Form1 from inside MyClass?

edit:

i solved it using events.
[/quote]

Egad!  Why?  Why not just pass your Form instance to MyClass and then give your Form1 class some public instance-level functions?
February 2, 2005, 2:02 AM
shout
A code example for MydnFyre's reply:
[code]
class MyClass
{
private Form1 whatnot;

public MyClass()
{
whatnot = new Form1();
}

private void blah()
{
whatnot.iamamethod();
}
}
[/code]
February 2, 2005, 2:15 AM
Myndfyr
[quote author=shout link=topic=10395.msg97851#msg97851 date=1107310541]
A code example for MydnFyre's reply:
[code]
class MyClass
{
private Form1 whatnot;

public MyClass()
{
whatnot = new Form1();
}

private void blah()
{
whatnot.iamamethod();
}
}
[/code]
[/quote]

Yeah that's MyndFyre, thanks :P

Anyway, the reason this comes up is because VB6 people are used to just referencing their forms and crap via the name of the form rather than an instance variable.  If you make your MyClass object from within the Form, you can pass the instance of the Form as a parameter via "this".
February 2, 2005, 2:29 AM
mentalCo.
i dont know why i didnt think of that.  haha.  thanks.
February 2, 2005, 4:11 AM
shout
Sorry MyndFyre, but I am but a human who makes mistakes.
February 2, 2005, 9:57 PM

Search