473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

New to cSharp

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
Nov 15 '05 #1
2 1774
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
----------------------------------
Making waves on the Web
"MC D" <as***@earthtalk.com> wrote in message
news:ON*************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #2
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

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonathan Grobe | last post by:
From: Nigel Perry <nigel@cosc.canterbury.ac.nz> Newsgroups: news.announce.newgroups,news.groups Subject: RFD: comp.std.csharp Date: Tue, 08 Jul 2003 00:26:01 +0000 REQUEST FOR DISCUSSION (RFD)...
7
by: Eric Gunnerson | last post by:
If you would like to see this group created, please reply to this post, making sure you leave news.groups on the newsgroups line. "Nigel Perry" <nigel@cosc.canterbury.ac.nz> wrote in message...
5
by: Mr. x | last post by:
Hello, where can I find csharp tutorial/help/samples. *.chm file is preffered. Thanks :)
8
by: Nicolas | last post by:
How do I do a RaiseEvent in csharp I'm ok in VB but csharp confused me a lot. ******* code ******** private FileSystemWatcher watcher = new FileSystemWatcher(); public delegate void...
4
by: light_wt | last post by:
Hi I am taking the 2555 class and a lot of the material is over my head. I don't like the MS's book because there is no step-by-step on interacting with the VS.NET Is there good free resource...
2
by: anand | last post by:
Hi All, Are ownerdraw buttons supported in C# ? I have an active X control which I would like to use in CSharp. Buttons have a style BS_OWNERDRAW, and to do custom drawing you have to...
7
by: Peter Smirnov | last post by:
Sorry for this newbie question but as far as I heard one need at least VisualStudio to develop CSharp applications. Is this correct? Are there otherwise some command line tools like javac.exe and...
1
by: Preston | last post by:
hello all... My friend using vb.net made a DLL file which contains a Property Kkk(ByVal key As Object) in it, I use CSharp and reference this DLL file, but in csharp object browser, there is no...
2
by: news.microsoft.com | last post by:
Hi: I work in Csharp's parser files by LEX/YACC.Now I have only CSharp-lex.l and CSharp.y file,but they not have CSharp'comment Parse. this is a part of CSharp-lex.l. ........................
2
by: Karl | last post by:
Hi all, I'm reasonably new to csharp so you have to forgive me asking what may be a stupid question... As I said, I'm new to CSharp but in VB I was able to click anywhere on a DataGridView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.