467,083 Members | 1,261 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,083 developers. It's quick & easy.

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
  • viewed: 1459
Share:
2 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Sandeep | last post: by
86 posts views Thread by jopperdepopper | last post: by
6 posts views Thread by earthwormgaz | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.