473,554 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Newbie question : Form and Classes interaction

Hi,
I am using Visual Studio 2005 and am using Visual C#. I notice
that the program.cs creates an instance of a form and runs it. I have
a PictureBox in the form and a Class File x.cs and in the Class file
x.cs want to access some of the picturebox parameters e.g size but I
do not have access to these parameters. I could write a function in
form.cs to return these parameters but as I don't have access to an
instance of form I cannot call the function . How do I get around this
problem. I know I could pass the PictureBox as a parameter from the
form to the Class but I would like to know how classes interact with
the Form ??
Jun 27 '08 #1
2 2769
On Apr 29, 6:18*am, pat.saund...@su ngardps.com wrote:
Hi,
* * * * I am using Visual Studio 2005 and am using Visual C#. I notice
that the program.cs creates an instance of a form and runs it. I have
a PictureBox in the form and a Class File x.cs and in the Class file
x.cs want to access some of the picturebox parameters e.g size but I
do not have access to these parameters. I could write a function in
form.cs to return these parameters but as I don't have access to an
instance of form I cannot call the function . How do I get around this
problem. I know I could pass the PictureBox as a parameter from the
form to the Class but I would like to know how classes interact with
the Form ??
Hi,

I do not completely understand what you want, but you can pass a
parameter of type PictureBox to the class from the form
Jun 27 '08 #2
On Tue, 29 Apr 2008 03:18:49 -0700, <pa**********@s ungardps.comwro te:
I am using Visual Studio 2005 and am using Visual C#. I notice
that the program.cs creates an instance of a form and runs it. I have
a PictureBox in the form and a Class File x.cs and in the Class file
x.cs want to access some of the picturebox parameters e.g size but I
do not have access to these parameters. I could write a function in
form.cs to return these parameters but as I don't have access to an
instance of form I cannot call the function . How do I get around this
problem. I know I could pass the PictureBox as a parameter from the
form to the Class but I would like to know how classes interact with
the Form ??
As Ignacio says, you can pass the PictureBox instance reference to your X
class. This could be done via the constructor, or a method, or even by
setting a property. Based on the first clause of your last sentence, I
would even guess that you already know this.

But there's nothing magical about that. Your Form-derived class is just
another class. It works the same way as any other class, and thus other
classes "interact with the Form" in exactly the same way they would
interact with any other class. If you have a way to pass the PictureBox
reference to your X class, then you should be able to easily pass the
Form-derived class reference as well.

In particular, the PictureBox reference is, by default, only going to be
accessible from code within your Form-derived class. So if you're passing
that reference -- for example, "pictureBox 1" -- you could just as easily
pass the reference to the Form, using "this".

Not that this is specifically related to your question, but IMHO it's not
usually a good idea to pass references to control instances contained
within a Form-derived class to some other class. In very specific
situations it might be okay, but most of the time you will want your
Form-derived class to keep the controls hidden, exposing only specific
characteristics of those controls in very limited ways. For example, if
you want some other class to be able to get the size of a PictureBox,
create a new read-only property (i.e. has only a getter) on the
Form-derived class that returns the size. Then the class that needs the
size will need a reference to the Form-derived class, not the PictureBox
itself, and will retrieve the size of the PictureBox indirectly through
the Form-derived class's property.

So I think you're right to want to know about passing the Form-derived
class reference to class X rather than the PictureBox reference. However,
it's not really clear what issue you're having, since you seem to already
have all of the basic parts (i.e. you know you can pass a reference to
another class, and you apparently already have a situation where you have
access to the PictureBox reference, and thus have access to the
Form-derived class reference).

If the above doesn't clear things up, maybe you could post a simple,
minimal code example that shows what you have so far, and how you want it
to change to allow whatever it is you're doing.

Pete
Jun 27 '08 #3

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

Similar topics

8
2509
by: CJM | last post by:
For the majority of my work, I just use plain ASP. On the rare occasion that I am doing something intensive that does require user interaction I might create a COM component (ie where performance gain outweighs the overhead of COM). A simple Rule-of-Thumb. I imagine this is fairly common practice... (I hope it is, at least). However, I'm...
5
1860
by: John | last post by:
Hi, I need some software that will analyze my C# application (consisting of multiple projects and many classes) and show the relationships between classes and methods. I want to visually see what methods are called from each class. Is there anything free that can do this?
8
4401
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and click a button to determine whether the zip code is unique. If the zip code is not unique, another form/dialog is displayed (fclsLookup) - lookup...
0
1669
by: David Virgil Hobbs | last post by:
While studying the asp.net javascript problem I saw and used pages about asp.net basics at http://www.sitepoint.com/article/815/4 and http://www.aspfree.com/c/a/ASP.NET/ASPNET_Basics_part_1_Nothing_But_Net/3/ I have put together an aspx page ( http://www34.brinkster.com/vincemoon/3assignment.aspx ) wherein I attempt to read and write to...
2
8987
by: thomasp | last post by:
Using VB 2005 Beta. I have a form containing a DataGirdView. The cell enter, cell validating, row enter, row validating events have a good bit of code that gets excuted for each of these events. I have noticed that when the form loads, each of these events run 3 times, before the form is ready for interaction with the user. I would like...
3
14338
by: Vitaly Zayko | last post by:
Is it possible to attach a form (C# .NET 2) to windows service and show it in OnStart event? When I tried to do this in general (new, Show()) way it just didn't do anything nor gave me any errors. I want to use this form for interaction with the service. Thanks! Vit Zayko
5
2083
by: Mike Dee | last post by:
Is it possible to dynamically create a new form object (form1), then create a new form field object and add it form1, and then add form1 to the current document? I need to do all this in script rather than using the html <form> and related tags. Can this be done to support both IE, Firefox? Any code snippets or samples showing how to do...
19
1538
by: AMP | last post by:
I have a simple question. If i have a button on form1 that creates : Form2 newform = new Form2(); newform.Show(); As I click the button a new form shows,but acording to my code each one has the same name.Are they really there(I can move them around and close them).If they are how do they have the same name (to refer to in code).
4
1820
by: wageslave | last post by:
Hi folks, I have a question about using consequtive combo boxes on a form. I am designing a basic library database for a small community organisation which deals with inner city problems and issues. They don't have a librarian on staff so I am trying to make things as easy as possible for them. To help them catalogue new items I have...
0
7581
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7506
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7782
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8018
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7872
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6123
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5423
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3533
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2006
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.