New to cSharp

  • Thread starter Thread starter Rick Strahl [MVP]
  • Start date Start date
R

Rick Strahl [MVP]

D

By default properties on a form are marked protected which means it's
visible within the same class or any of its subclasses. From within form
code snippets you should always be able to access a property with
this.<propertyName>.

If you pass the form as a reference to another external object though you
can no longer access any of the protected properties because they are scoped
to the form or its subclasses.

I'm not sure why your code isn't working if you are indeed in a form method
and ontop of it your accessor is set to public. You might want to make sure
you have the right property and class that you're dealing with.

Regards,

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/wwHelp
 
Could someone explain this to me... there is something I don't understand
about control "scope". I have a picturebox on Form1, but If I try to access
the properties of the picturebox (width and height), I get an error
regarding the protection level. This is from within the Form1 class. I have
it's modifiers set as "public"... what gives? If I try and modify the
declaration to make it static, I also get an error. (Can't remember which
one now though). What is the correct way of accessing the control?

Can you please post your code and the exact error message you're
getting.

Also, how do you access an instance of a form from an object? Does the form
have to be passed to the object?
Yes


That seems confusing.

How so? A Form instance isn't different from other objects in this
regard.

If I wanted to
write a custom class to handle painting to the picturebox mentioned above,
would the form itself need to be passed as a parameter to the object, or
can't the object just look for the instance of Form1 somehow?

Either the Form or just the PictureBox.



Mattias
 
Could someone explain this to me... there is something I don't understand
about control "scope". I have a picturebox on Form1, but If I try to access
the properties of the picturebox (width and height), I get an error
regarding the protection level. This is from within the Form1 class. I have
it's modifiers set as "public"... what gives? If I try and modify the
declaration to make it static, I also get an error. (Can't remember which
one now though). What is the correct way of accessing the control?

Also, how do you access an instance of a form from an object? Does the form
have to be passed to the object? That seems confusing. If I wanted to
write a custom class to handle painting to the picturebox mentioned above,
would the form itself need to be passed as a parameter to the object, or
can't the object just look for the instance of Form1 somehow?

Sorry so dense...

-D
 
Back
Top