jamesnoe
asked on
Static (IsShared) property keeps getting reset
Hi there,
I have a control that I want to use in several files.
I have therefore set it up as:
public static System.Windows.Forms.Label label1;
All references to this in my main application I have changed from "this.label1" to "label1". In the other classes that I want to use this in, I inherit the main application and use "label1".
This all works.
However Visual Studio (.Net 2003 C#) keeps on automatically (every now and then) changing this back to the defaults:
public System.Windows.Forms.Label label1; // NO STATIC
And it changes all "label1" to "this.label1"
Has anyone experienced this? It's very annoying!
Hope you can help.
Thanks,
James
I have a control that I want to use in several files.
I have therefore set it up as:
public static System.Windows.Forms.Label
All references to this in my main application I have changed from "this.label1" to "label1". In the other classes that I want to use this in, I inherit the main application and use "label1".
This all works.
However Visual Studio (.Net 2003 C#) keeps on automatically (every now and then) changing this back to the defaults:
public System.Windows.Forms.Label
And it changes all "label1" to "this.label1"
Has anyone experienced this? It's very annoying!
Hope you can help.
Thanks,
James
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
But I have!
I have one file (let's call it myConstants) which looks like:
using System;
namespace My_Namespace
{
public class myConstants
{
public static System.Windows.Forms.Label label1;
public myConstants()
{
}
}
}
In my MainApp file I have:
namespace My_Namespace
{
public class MainApp : System.Windows.Forms.Form
{
......... stuff here ..........
private void InitializeComponent()
{
myConstants.label1= new System.Windows.Forms.Label ();
this.summaryBox.Controls.A dd(myConst ants.label 1);
}
}
There's obviously loads of stuff cut out - but am I doing something daft?
I'm quite new to C# - so apologies if this is daft.
Thanks for the quick responses.
Cheers,
James
I have one file (let's call it myConstants) which looks like:
using System;
namespace My_Namespace
{
public class myConstants
{
public static System.Windows.Forms.Label
public myConstants()
{
}
}
}
In my MainApp file I have:
namespace My_Namespace
{
public class MainApp : System.Windows.Forms.Form
{
......... stuff here ..........
private void InitializeComponent()
{
myConstants.label1= new System.Windows.Forms.Label
this.summaryBox.Controls.A
}
}
There's obviously loads of stuff cut out - but am I doing something daft?
I'm quite new to C# - so apologies if this is daft.
Thanks for the quick responses.
Cheers,
James
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi there,
Really odd! I used your code, and I essentially get the same behaviour. When I run the app I can see label1 - but when I go to the design view, I can't see it.
I copy/pasted your code in so I don't know if it's the code - any weird settings in Visual Studio...?
Any other coding options?
Thanks,
James
Really odd! I used your code, and I essentially get the same behaviour. When I run the app I can see label1 - but when I go to the design view, I can't see it.
I copy/pasted your code in so I don't know if it's the code - any weird settings in Visual Studio...?
Any other coding options?
Thanks,
James
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi.
Thanks for all the comments - however I simply can't get it working.
What I've done now is rather than using static variables, I'm simply passing by reference.
I think this is a bug in Visual Studio
Thanks again,
James
Thanks for all the comments - however I simply can't get it working.
What I've done now is rather than using static variables, I'm simply passing by reference.
I think this is a bug in Visual Studio
Thanks again,
James
ASKER
All I want to do is have a control that I can see, move around, edit etc... in the design view, and access it in multiple files without Visual Studio messing it up!
Thanks,
James