melanieab wrote:
Hi,
I kind of got thrown into C# without any real programming experience,
so I know this is probably an easy question, but it's driving me
crazy. In my Tabs class, as I'm leaving a tabpage, I'm trying to
capture the screen as a bitmap. I'm trying to tell it to call the
CaptureTab method from a class called Print.
private void tabLeave(object sender, System.EventArg s e)
{
...
Print.CaptureTa b(System.Window s.Forms.Form frm);
}
but I get an error inside the parentheses - it's unhappy with frm and
says ) expected. Then I erase the frm to get the
'System.Windows .Forms.Form' denotes a 'class' where a 'variable' was
expected error. Then I try just (frm) and get The name 'frm' does
not exist in the class or namespace 'HCAUT.Tabs'. Then when I use
(this) I get An object reference is required for the nonstatic
field, method, or property
HCAUT.Print.Cap tureTab(System. Windows.Forms.F orm)'. I try (e) and
get The best overloaded method match for
'HCAUT.Print.Ca ptureTab(System .Windows.Forms. Form)' has some invalid
arguments. And finally I just leave it empty and get No overload
for method 'CaptureTab' takes '0' arguments. (My CaptureTab method
looks like this:
CaptureTab(Syst em.Windows.Form s.Form frm))
Anybody know what I can do to get this to work?
Thanks for any help!!!!
Melanie
To start at the end:
The method definition "CaptureTab(Sys tem.Windows.For ms.Form frm)"
means: this is a method with name "CaptureTab ". It accepts a single parameter
of type "System.Windows .Forms.Form", which internally is called "frm".
By the way: you didn't specify a returntype, which is required (although
it can be "void", meaning "nothing returned").
When you call this method, you will have to supply a variable
of the correct type (System.Windows .Forms.Form), or one which is
derived from that type (some specific form definition in this case).
If you supply a variable, the only requirement is that the *type* matches,
the *name* is irrelevant.
When you write
Print.CaptureTa b(System.Window s.Forms.Form frm);
you are *declaring* a new variable (frm), but this is illegal at this point.
When you declare a variable, you only define a space where later
some real data is placed.
So you need to find some way to get a reference to the particular form
that you want to "CaptureTab ". Sort of:
System.Windows. Forms.Form myFrm;
myFrm = ??????
Print.CaptureTa b(myFrm);
If you have the tabLeave method inside a form, then you could use "this"
to supply the current form to your CaptureTab method.
either use
myFrm = this;
in the lines above, or just replace all three with
Print.CaptureTa b(this);
But this is pretty basic stuff, maybe you should find some "introducti on
to programming" book to get some basis.
Hans Kesting