Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Class properties - how to change values from form

Class properties - how to change values from form

Scheduled Pinned Locked Moved C#
tutorialcsharpcssgraphicsdata-structures
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    peropata
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • P peropata

      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

      D Offline
      D Offline
      Dan Mos
      wrote on last edited by
      #2

      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.

      P 1 Reply Last reply
      0
      • D Dan Mos

        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.

        P Offline
        P Offline
        peropata
        wrote on last edited by
        #3

        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 in myGraphGridClass. In this case I would have to transfer values from myDivisionClass object to myGraphGridClass object which is created in myDivisionClass. I want ro know if there is a way to directly change properties defined in myGraphGridClass. Pata

        D 1 Reply Last reply
        0
        • P peropata

          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 in myGraphGridClass. In this case I would have to transfer values from myDivisionClass object to myGraphGridClass object which is created in myDivisionClass. I want ro know if there is a way to directly change properties defined in myGraphGridClass. Pata

          D Offline
          D Offline
          Dan Mos
          wrote on last edited by
          #4

          I don't know much the inner works of myDivisionClass or myGraphGridClass . But one way would be to pass the myGraphGridClass too in the ctor. It's an object so you pass the reference to it. And by modifyng the myGraphGridClass 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.

          P 1 Reply Last reply
          0
          • D Dan Mos

            I don't know much the inner works of myDivisionClass or myGraphGridClass . But one way would be to pass the myGraphGridClass too in the ctor. It's an object so you pass the reference to it. And by modifyng the myGraphGridClass 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.

            P Offline
            P Offline
            peropata
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups