Class properties - how to change values from form
-
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 frommyGraphGridClass
. 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 -
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 frommyGraphGridClass
. 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, Pataperopata wrote:
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 ) ...
just put the this.Owner == toYourMDIParent for each of the child.
peropata wrote:
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.
There are many options: One would be to Create a Custom/User Control that encapsuletes your graph form and in that control put the comboboxes textboxes, etc to alter/modify different properties of the graph Or if you want a setup/properties button create a new form that deals with the different properties and in the ctor pass in your graph eg:
SetupForm sf = new SetupForm(this.myGraph)
or something like this.
-
peropata wrote:
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 ) ...
just put the this.Owner == toYourMDIParent for each of the child.
peropata wrote:
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.
There are many options: One would be to Create a Custom/User Control that encapsuletes your graph form and in that control put the comboboxes textboxes, etc to alter/modify different properties of the graph Or if you want a setup/properties button create a new form that deals with the different properties and in the ctor pass in your graph eg:
SetupForm sf = new SetupForm(this.myGraph)
or something like this.
Or if you want a setup/properties button create a new form that deals with the different properties and in the ctor pass in your graph:
SetupForm sf = new SetupForm(this.myGraph)
This code would work for setting properties defined in
myDivisionClass
class, and not for properties defined inmyGraphGridClass
. In this case I would have to transfer values frommyDivisionClass
object tomyGraphGridClass
object which is created inmyDivisionClass
. I want ro know if there is a way to directly change properties defined inmyGraphGridClass
. Pata -
Or if you want a setup/properties button create a new form that deals with the different properties and in the ctor pass in your graph:
SetupForm sf = new SetupForm(this.myGraph)
This code would work for setting properties defined in
myDivisionClass
class, and not for properties defined inmyGraphGridClass
. In this case I would have to transfer values frommyDivisionClass
object tomyGraphGridClass
object which is created inmyDivisionClass
. I want ro know if there is a way to directly change properties defined inmyGraphGridClass
. PataI don't know much the inner works of
myDivisionClass
ormyGraphGridClass
. But one way would be to pass themyGraphGridClass
too in the ctor. It's an object so you pass the reference to it. And by modifyng themyGraphGridClass
in your SetupForm, you are actually modifyng the one in your child window(s). All you need to do is call the Invalidate() or refresh method on the grid or the child form, once you close the setupForm. Or directly from the setup form. The possibilities are countless and you know better what you want. -
I don't know much the inner works of
myDivisionClass
ormyGraphGridClass
. But one way would be to pass themyGraphGridClass
too in the ctor. It's an object so you pass the reference to it. And by modifyng themyGraphGridClass
in your SetupForm, you are actually modifyng the one in your child window(s). All you need to do is call the Invalidate() or refresh method on the grid or the child form, once you close the setupForm. Or directly from the setup form. The possibilities are countless and you know better what you want.I found the problem. It was my mistake in creating objects. I was creating object
MyGraphGridClass
inside one of the method ofMyDivisionClass
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 myMyDivisionClass
, 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