reference a form

  • Thread starter Thread starter Mike J
  • Start date Start date
M

Mike J

Hi i have a class running
how do i reference from within the class
the form

class myclass
{
}
public myclass(object ofrm)
i can't see the form at develop time to see its type
if i use object will not compile
object oform=ofrm;
im still lil new at c#
tia
MJ
 
Mike said:
Hi i have a class running
how do i reference from within the class
the form

class myclass
{
}
public myclass(object ofrm)
i can't see the form at develop time to see its type
if i use object will not compile

Depends on what you want to /do/ with the Form within your method.

If using it as a Forms.Form is good enough - say, to move it around on
the screen - then ...

public myclass(System.Windows.Forms.Form ofrm)

.... would do.

If you want to do something more /specific/ - like calling a "known"
method on that form - then you're [almost certainly] going to have to
/get/ the Type of the Form at design time. Without this, you're reduced
to Late Bound execution that usually results in more trouble (i.e.
run-time errors) than it's worth.

/Why/ don't you know the Type of the Form at design time?
Is this some sort of "plug-in" model (in which case, an Interface might
be the way to go).

HTH,
Phill W.
 
i do know the form type.....
what i have is a Service running and executing a class to process sql
data........
also i have a front end app..for testing this service class
so i want to update come text boxes of the process while its running.....eg
Test mode
Tks
MJ



Phill W. said:
Mike said:
Hi i have a class running
how do i reference from within the class
the form

class myclass
{
}
public myclass(object ofrm)
i can't see the form at develop time to see its type
if i use object will not compile

Depends on what you want to /do/ with the Form within your method.

If using it as a Forms.Form is good enough - say, to move it around on the
screen - then ...

public myclass(System.Windows.Forms.Form ofrm)

... would do.

If you want to do something more /specific/ - like calling a "known"
method on that form - then you're [almost certainly] going to have to
/get/ the Type of the Form at design time. Without this, you're reduced
to Late Bound execution that usually results in more trouble (i.e.
run-time errors) than it's worth.

/Why/ don't you know the Type of the Form at design time?
Is this some sort of "plug-in" model (in which case, an Interface might be
the way to go).

HTH,
Phill W.
 
Back
Top