Newbie: class access questions

G

Geoff Collier

I have a form called frm_junk. On it there is a rich
text box called rtxt_output. I am having trouble
accessing this (or any) object on frm_junk from another
class. I have a class "test". When I tried to access
rtxt_output from "test" I got an error message indicating
that the protection level of rtxt_output did not allow
access. So, I converted rtxt_output to public. However,
when I try to type something like:
rtxt_output.Text="hello";
class "test" does not see rtxt_output. This is true even
if I try to use:
frm_junk.rxt_output.Text.
The error message I get is:
C:\Documents and Settings\Owner\My Documents\Visual
Studio Projects\junk\Form1.cs
(123): 'junk.frm_junk.rtxt_output' denotes a 'field'
where a 'class' was expected
Any enlightment on these access problems are greatly
apprediated, thanks.
 
G

Goran Genter

Geoff Collier said:
I have a form called frm_junk. On it there is a rich
text box called rtxt_output. I am having trouble
accessing this (or any) object on frm_junk from another
class. I have a class "test". When I tried to access
rtxt_output from "test" I got an error message indicating
that the protection level of rtxt_output did not allow
access. So, I converted rtxt_output to public. However,
when I try to type something like:
rtxt_output.Text="hello";
class "test" does not see rtxt_output. This is true even
if I try to use:
frm_junk.rxt_output.Text.

frm_junk is class or instance of that class.
If it is the name of class rxt_output must be static if you would like to
access it.
But you should do that.

In test class constructor you should pass reference to an instance of
frm_junk :
test t = new test(frm_junk_instance) //for example

then you should be able to call :
frm_junk.rxt_output.Text = "hello"
 
G

Geoff Collier

In test class constructor you should pass reference to an instance of
frm_junk :
test t = new test(frm_junk_instance) //for example

then you should be able to call :
frm_junk.rxt_output.Text = "hello"

I'm not sure how to do this. In main I have the standard
call:
Application.Run(new frm_junk());
I gather that this gives me an unnamed instance of
frm_junk.
I have changed the constructor for class test to:
public test(int n,frm_junk myform) //constructor
I then changed the call to this class to:
test mytest;
mytest=new test(5,new frm_junk());
Now, the attempt to access the rich text box in frm_junk
within class test is:
myform.rtxt_output.Text=data.ToString();
However, I get the error message:

C:\Documents and Settings\Owner\My Documents\Visual
Studio Projects\junk\Form1.cs(138): The type or namespace
name 'myform' could not be found (are you missing a using
directive or an assembly reference?)
THANKS!
 
T

Thomas Delrue

On Mon, 1 Sep 2003 09:33:51 -0700, "Geoff Collier"

SNIP
test mytest;
mytest=new test(5,new frm_junk()); ....
myform.rtxt_output.Text=data.ToString();
However, I get the error message:

C:\Documents and Settings\Owner\My Documents\Visual
Studio Projects\junk\Form1.cs(138): The type or namespace
name 'myform' could not be found (are you missing a using
directive or an assembly reference?)
THANKS!



Try using mytest instead of myForm :)
 
G

Geoff Collier

-----Original Message-----
On Mon, 1 Sep 2003 09:33:51 -0700, "Geoff Collier"

SNIP
test mytest;
mytest=new test(5,new frm_junk()); ....
myform.rtxt_output.Text=data.ToString();
However, I get the error message:

C:\Documents and Settings\Owner\My Documents\Visual
Studio Projects\junk\Form1.cs(138): The type or namespace
name 'myform' could not be found (are you missing a using
directive or an assembly reference?)
THANKS!



Try using mytest instead of myForm :)


rtxt_output is on myform. mytest is a separate class.????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top