Hi Nacho,

Better don't use Program.cs to declare the property.
Instead declare another static class just to declare variables across the
application.
Something like a Statemanager.cs
Just let me know if this helps.

Regards,
Nikhil

On Wed, Feb 18, 2009 at 9:36 PM, Nacho108 <[email protected]> wrote:

>
> Hi everyone,
> I'm trying to create an structure so it can be seen from all forms. So
> doing a bit of research I decided to create an static property of the
> main class of the program.
>
> For this I've made this code:
>
> namespace WindowsApplication1
> {
>    static class Program
>    {
>        public struct Seleccion
>        {       public bool x;
>                public bool y;         }
>
>        private static Seleccion sel_activa ;
>
>        public static Seleccion _sel_activa
>        {        get { return Program.sel_activa;}
>                 set { Program.sel_activa =value; }        }
>
>        static void Main()
>        {  Program.sel_activa = new Seleccion();
>            Application.EnableVisualStyles();
>            Application.SetCompatibleTextRenderingDefault(false);
>            Application.Run(new Form1());        }
> } }
>
> and after doing this I try to access the property from one form like
> this:
>
> Program._sel_activa.x = B02.Checked;    (B02 is a check box)
>
> and VS throw me an exception:
> "Cannot modify the return value of
> 'WindowsApplication1.Program._sel_activa' because it is not a
> variable"
>
> Can somebody help with this?
>
> By the way this is the link of the article I've taken from the
> information.
>
> http://bytes.com/groups/net-c/263680-accessing-same-data-multiple-forms-using-c
>
> Thanks in advance!
>
>

Reply via email to