Hello,
If I have a static control and 2 forms, each of which references the
static. When I return from the 2nd and go back to the first, the
reference to static control appears to have been removed altogether. It
disappears from the first form.
If you run the following example, click "DerivedFor m1" then close it
(ok). Then click "DerivedFor m2" and close that.
When you click DerivedForm1 again, the "Something" button has vanished.
I tested this on .NETCF. Is it a problem? If not, would someone explain
why this happens?
Cheers,
..pd.
using System;
using System.Drawing;
using System.Collecti ons;
using System.Windows. Forms;
using System.Data;
namespace ToggleSubscribe r
{
public class Form1 : System.Windows. Forms.Form
{
DerivedForm1 df1;
DerivedForm2 df2;
public static Button the_button;
public Form1()
{
the_button = new Button();
MinimizeBox = false;
Button b1 = new Button();
b1.Text = "DerivedFor m1";
b1.Size = new Size(100, 20);
b1.Location = new Point(60, 40);
Button b2 = new Button();
b2.Size = new Size(100, 20);
b2.Text = "DerivedFor m2";
b2.Location = new Point(60, 80);
b1.Click += new EventHandler(b1 _Click);
b2.Click += new EventHandler(b2 _Click);
Controls.Add(b1 );
Controls.Add(b2 );
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
static void Main()
{
Application.Run (new Form1());
}
private void b1_Click(object sender, EventArgs e)
{
if (df1 == null)
df1 = new DerivedForm1(th e_button);
df1.Show();
}
private void b2_Click(object sender, EventArgs e)
{
if (df2 == null)
df2 = new DerivedForm2(th e_button);
df2.Show();
}
}
public class BaseForm : Form
{
public delegate void OnSomethingHapp ens(object sender,
EventArgs e);
public event OnSomethingHapp ens SomethingHappen ed;
private Button b;
public BaseForm(Button btn)
{
MinimizeBox = false;
b = btn;
b.Location = new Point(60, 60);
b.Text = "Something" ;
b.Click += new EventHandler(b_ Click);
Controls.Add(b) ;
}
private void b_Click(object sender, EventArgs e)
{
if (SomethingHappe ned != null)
SomethingHappen ed(sender, e);
}
}
public class DerivedForm1 : BaseForm
{
BaseForm.OnSome thingHappens del;
public DerivedForm1(Bu tton btn) : base(btn)
{
del = new OnSomethingHapp ens(DerivedForm 1
_SomethingHappe ned);
SomethingHappen ed += del;
Closing += new System.Componen tModel.CancelEv entHandler
(DerivedForm1_C losing);
}
private void DerivedForm1_So methingHappened (object sender,
EventArgs e)
{
MessageBox.Show ("Something happened in DerivedForm1");
}
private void DerivedForm1_Cl osing(object sender,
System.Componen tModel.CancelEv entArgs e)
{
SomethingHappen ed -= del;
this.Visible = false;
e.Cancel = true;
}
}
public class DerivedForm2 : BaseForm
{
BaseForm.OnSome thingHappens del;
public DerivedForm2(Bu tton btn) : base(btn)
{
del = new OnSomethingHapp ens(DerivedForm 1
_SomethingHappe ned);
SomethingHappen ed += del;
Closing += new System.Componen tModel.CancelEv entHandler
(DerivedForm1_C losing);
}
private void DerivedForm1_So methingHappened (object sender,
EventArgs e)
{
MessageBox.Show ("Something happened in DerivedForm2");
}
private void DerivedForm1_Cl osing(object sender,
System.Componen tModel.CancelEv entArgs e)
{
SomethingHappen ed -= del;
e.Cancel = true;
this.Visible = false;
}
}
} 0 1275 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: joe martin |
last post by:
Hey all,
For singleton code that looks like this:
class JoeClass
{
friend JoeClass &joeFunction();
private:
JoeClass() { someFunction();}
}
|
by: .pd. |
last post by:
Hello,
If I have a static control and 2 forms, each of which references the
static. When I return from the 2nd and go back to the first, the
reference to static control appears to have been removed altogether. It
disappears from the first form.
If you run the following example, click "DerivedForm1" then close it
(ok). Then click "DerivedForm2" and close that.
|
by: Clint |
last post by:
Hey all -
Excuse the cross-post ... I'm not sure what the appropriate newsgroup
would be for this question.
I have a question that I'm not quite sure how to ask. For all I know, I
have the verbaige completely wrong, but here goes nothing ...
I'm currently using the MS Data Access Block for a desktop application
I'm writing. Recently, I had to add a call to a web service, which in
|
by: Gery D. Dorazio |
last post by:
Gurus,
If a static variable is defined in a class what is the scope of the variable
resolved to for it to remain 'static'? For instance, lets say I create a
class library assembly that is strongly name which contains the class where
the static variable is defined. This library can be referenced by multiple
projects. I am fairly sure the static variable does not survive across the
application boundry but does it within the application...
|
by: Tony Wong |
last post by:
I am trying to implement the Singleton Pattern for a assembly (class) which
control a common resource on my computer. I need the Singleton behavior
within a single process which contain multiple AppDomains. I use a static
member to count class instance like this,
public __gc class foo: public IDisposable
{
public:
| |
by: Joe Fallon |
last post by:
In another post Kevin Spencer stated: "one should be careful of using static
fields, properties, and methods, by understanding what the implications of
such are (e.g. locking static variables when changing because they are not
thread-safe)."
Can someone please elaborate on the pros and cons of using static methods?
(In VB they are called Shared methods.) The MS DAAB uses Shared methods.
This means that all Data Access calls go through...
|
by: Tom Pearson |
last post by:
What is the scope of static variable when programming in ASP.NET?
For example I have a control class that uses static callbacks so that another window can pass a list of items to it. The control doesn't have access to this other object so needs to subscribe to the static callback. As such the static callback then needs to get hold of the real control instance which it can do via a member vaiarble which is set to the instance of the control on...
|
by: |
last post by:
Hi,
How long do webservice objects live for? In particular, if i have static
variables filled with data from a static constructor in a webservice, how
long will that data persist?
thxs
|
by: Jeroen |
last post by:
Hi all,
I've got a question about writing a library. Let me characterize that
library by the following:
* there is a class A which is available to the user
* there is a class B that is used in severel 'underwater operations'
* there is a list which stores objects of class B
There are several issues I'm not sure about:
|
by: Dave |
last post by:
I have a global.asax file with Application_Start defined and create some
static data there and in another module used in the asp.net application and
I realize that static data is shared amongst child apps of an IIS
application and can be used by multiple users during the application life
cycle and for multiple page loads for the same or different page under a
root application.
What I don't understand and need to know is whether that...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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,...
|
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,...
|
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...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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();...
|
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...
| |
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |