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 1281 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: 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...
| |
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...
|
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: 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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |