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

G

Greg Merideth

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?
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top