472,353 Members | 1,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

accessing public members of different classes which i can't derivefrom..

Using Visual C# I created two forms such as

namespace test
{
public class SystemTray : System.Windows.Forms.Form
{
public createwindow() { stuff here; }
public fadewindow() { stuff to fade here; }
public displaystuffinwindow() { display stuff here; }
}

public class LabelArray : System.Collections.CollectionBase
{
public make-label-array() { do stuff }

here's the tricky part

public click_handler()
{
make a generic click handler for the array of 20 label's on
the form
}
}

I would like the click_handler() to be able to call the "fadewindow()"
function even thou its in a different class but I can't get at it since
..net wont let me use multiple inheritance. I can't seem to get a
referecne to the window from the LabelArray class either.

This is a system tray application that has no main window. Based upon
menu options I create forms and create the elements in the form. When a
user clicks on the item I need the click_handler (in a different class)
to be able to close that window which..i can't seem to do since the
click_handler has no way to 'see' that window.

Hope I made that clear enough cause it sure as hell confuses me. Any
ideas how to get a form to access elements in another form in a
different class without being able to inherit it?
Nov 15 '05 #1
2 1621
Greg,

A form or a control is nothing more than an object. In that sense, you
can just pass it as you would anything else in .NET and access the
properties and methods on that instance as needed. For example, when you
want to read the contents of a stream into a dataset, you pass a class
derived from Stream to the ReadXml method on the DataSet. A form is no
different. Just pass the instance of the form to the LabelArray.

If you want the click_handler method (which BTW, violates the naming
conventions for public members that MS has put out, as do your other
methods), then you can just create a new instance of EventHandler, wrapping
the click_handler method. Once you have that, just assign it to the click
event of all of your labels, and it should work fine.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Merideth" <gm*******@removethis.uclabs.com> wrote in message
news:aM********************@comcast.com...
Using Visual C# I created two forms such as

namespace test
{
public class SystemTray : System.Windows.Forms.Form
{
public createwindow() { stuff here; }
public fadewindow() { stuff to fade here; }
public displaystuffinwindow() { display stuff here; }
}

public class LabelArray : System.Collections.CollectionBase
{
public make-label-array() { do stuff }

here's the tricky part

public click_handler()
{
make a generic click handler for the array of 20 label's on
the form
}
}

I would like the click_handler() to be able to call the "fadewindow()"
function even thou its in a different class but I can't get at it since
.net wont let me use multiple inheritance. I can't seem to get a
referecne to the window from the LabelArray class either.

This is a system tray application that has no main window. Based upon
menu options I create forms and create the elements in the form. When a
user clicks on the item I need the click_handler (in a different class)
to be able to close that window which..i can't seem to do since the
click_handler has no way to 'see' that window.

Hope I made that clear enough cause it sure as hell confuses me. Any
ideas how to get a form to access elements in another form in a
different class without being able to inherit it?

Nov 15 '05 #2
I tried that but as I looked at the code I must have
gotten it wrong so I'll go back and try till I get it (its
how I've learned 99% of c#). What naming convention did
MS publish about naming methods?

I usually use hungarian naming but the example was just a
quick throw together of what i was looking for.
-----Original Message-----
Greg,

A form or a control is nothing more than an object. In that sense, youcan just pass it as you would anything else in .NET and access theproperties and methods on that instance as needed. For example, when youwant to read the contents of a stream into a dataset, you pass a classderived from Stream to the ReadXml method on the DataSet. A form is nodifferent. Just pass the instance of the form to the LabelArray.
If you want the click_handler method (which BTW, violates the namingconventions for public members that MS has put out, as do your othermethods), then you can just create a new instance of EventHandler, wrappingthe click_handler method. Once you have that, just assign it to the clickevent of all of your labels, and it should work fine.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Merideth" <gm*******@removethis.uclabs.com> wrote in messagenews:aM********************@comcast.com...
Using Visual C# I created two forms such as

namespace test
{
public class SystemTray : System.Windows.Forms.Form
{
public createwindow() { stuff here; }
public fadewindow() { stuff to fade here; }
public displaystuffinwindow() { display stuff here; } }

public class LabelArray : System.Collections.CollectionBase {
public make-label-array() { do stuff }

here's the tricky part

public click_handler()
{
make a generic click handler for the array of 20 label's on the form
}
}

I would like the click_handler() to be able to call the "fadewindow()" function even thou its in a different class but I can't get at it since .net wont let me use multiple inheritance. I can't seem to get a referecne to the window from the LabelArray class either.
This is a system tray application that has no main window. Based upon menu options I create forms and create the elements in the form. When a user clicks on the item I need the click_handler (in a different class) to be able to close that window which..i can't seem to do since the click_handler has no way to 'see' that window.

Hope I made that clear enough cause it sure as hell confuses me. Any ideas how to get a form to access elements in another form in a different class without being able to inherit it?

.

Nov 15 '05 #3

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

Similar topics

5
by: Sandeep | last post by:
Hi, In the following code, I wonder how a private member of the class is being accessed. The code compiles well in Visual Studio 6.0. class...
2
by: Steven T. Hatton | last post by:
I find the surprising. If I derive Rectangle from Point, I can access the members of Point inherited by Rectangle _IF_ they are actually members of...
2
by: Rafe Culpin | last post by:
Does anyone please know of a way to access static methods of a class, when the name of that class is held in a variable? I have several classes...
9
by: Rudy | last post by:
Hello All! I'm a little confused on Public Class or Modules. Say I have a this on form "A" Public Sub Subtract() Dim Invoice As Decimal Dim...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I...
6
by: earthwormgaz | last post by:
Is the following legal? class Outer { class Inner { private: Inner() { } };
26
by: Zytan | last post by:
What happens if I do this: static byte MemberFunction() instead of: public static byte MemberFunction() I know I can't access it. But what...
12
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
6
by: Bhawna | last post by:
I am into c++ code maintenance for last 3-4 years but recently I am put into design phase of a new project. Being a small comapany I dont have...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.