473,657 Members | 2,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 displaystuffinw indow() { display stuff here; }
}

public class LabelArray : System.Collecti ons.CollectionB ase
{
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 1694
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.co m

"Greg Merideth" <gm*******@remo vethis.uclabs.c om> wrote in message
news:aM******** ************@co mcast.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 displaystuffinw indow() { display stuff here; }
}

public class LabelArray : System.Collecti ons.CollectionB ase
{
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.co m

"Greg Merideth" <gm*******@remo vethis.uclabs.c om> wrote in messagenews:aM******* *************@c omcast.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 displaystuffinw indow() { display stuff here; } }

public class LabelArray : System.Collecti ons.CollectionB ase {
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
2408
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 Sample { private: int x; public:
2
2297
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 a Rectangle. If I have a member of type Point in Rectangle, the compiler tells me Point::x is protected. I would have expected Rectangle to see the protected members of any Point. Compiling the following code give me this error: g++ -o rectangle main.cc main.cc: In member function `size_t...
2
2634
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 (PHP5) which all have identically named methods and members. I want to pass the name of one of the classes to an included file which does some standard operations using those methods and members. (So several different programs can include that file, each passing a different class name.)
9
2349
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 Wage As Decimal Static PO As Decimal Invoice = CDec(txbInv.Text) Wage = CDec(txbTotWage.Text)
86
4607
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 quote the php manual: "The visibility of a property or method can be defined by prefixing the declaration with the keywords: public, protected or private. Public declared items can be accessed everywhere."
6
5028
by: earthwormgaz | last post by:
Is the following legal? class Outer { class Inner { private: Inner() { } };
26
2431
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 does it default to? Private? I can't find any code that does this, and "static" docs don't say much. thanks
12
4805
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
6
8152
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 enough guidance from seniors. Currently I am into a situation where I am implementing base class functions by including a pointer to subclass member in base class. Reason being functionality is common for subclasses but the members are common within subclass only (static member of subclass) but...
0
8310
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4158
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2731
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
2
1957
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.