Skip to content

Class properties - how to change values from form

Pata

Asked Mar 10, 2010, 11:39 AM EST1 answer
Share
LinkedInX
Hi, this is my first posting at this forum and I need some help with my project. I am new to c# and still confused at times ...
My application is as follow:
I have main MDI_ParentForm, from which I open a ChildForm. I use ChildForm as drawing area for my graph.
I am dividing ChildForm up into smaller areas (rectangles). This is done by creating new object:
            
myDivisionClass myGDI = new myDivisionClass(this) ;

In my class definition for myDivisionClass I create object for each reactangle (for example: first rectangle represents grid area, second title, third labels for traces and so on ...)

myGraphGridClass myGrid = new myGraphGridClass(myRectangle);
myGraphTitle myTitle = new myGraphTitle(myRectangle);
myGraphLabels myTitle = new myGraphLabels(myRectangle);
etc...

Now I want to add a setup form (shown when pressing button on ChildForm), from which I could change properties of my myGrid object from myGraphGridClass.
I would also like to be able to open any number of ChildForms and change properties for each individual ChildForm object (so each could display graph with different settings ) ...

tnx, Pata

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    I found the problem. It was my mistake in creating objects. I was creating object MyGraphGridClass inside one of the method of MyDivisionClass and as such it was destroyed as soon as it left that method and its properties could not be accessed. I rearranged a code and put the declaration (creation) of my object as one of the properties of my MyDivisionClass, so I can access its properties.

    class MyGraphGridClass
        {
            private int myProperty;

            public int Property
            {
                get { return myProperty; }
                set { myProperty = value; }
            }

            .
            .
            .

        }

        class MyDivisionClass
        {
            private MyGraphGridClass objMyGraphGrid = new MyGraphGridClass();

            internal MyGraphGridClass MyGraphGrid
            {
                get { return objMyGraphGrid; }
                set { objMyGraphGrid = value; }
            }

            .
            .
            .

        }

    // In chid form class

           MyDivisionClass Graph_01 = new MyDivisionClass();
           MyDivisionClass Graph_02 = new MyDivisionClass();

           Graph_01.MyGraphGrid.Property = 5;
           Graph_02.MyGraphGrid.Property = 3;
           
           // and then use as suggested
           SetupForm sf = new SetupForm(Graph_01.MyGraphGrid);

    Pata
    0