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. object oriented(class inheritance)???????

object oriented(class inheritance)???????

Scheduled Pinned Locked Moved C#
oophelpquestioncsharp
4 Posts 3 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.
  • M Offline
    M Offline
    mr mohsen
    wrote on last edited by
    #1

    hi friends i have a question about object oriented(class inheritance) i have a windows application with c# that in this application i have 2 forms. these 2 forms have few methods i show you below. ========> form1 public partial class form1:Form { public form1() { InitializeComponent(); } public void change_value_label(string new_value) { lbl.Text=new_value;//this label defined as private controll for this form } } =========>form2 public partial class form2:Form { public form2() { InitializeComponent(); } private void subject_Load(object sender, EventArgs e) { //in this area code i want to write a code that call change_value_label method of form1 , but i can't // if i create a new object of form1 then i can call the method but with this way i cannot change the value of the label on form1 //and if i declare change_value_label method on form1 as static method then on the method i cannot access to the label because this controll is not static and i //cannot define the label as static control //please tell me what do i have to do to solve this problem? } } form1 and form2 are showing at te same time because this two forms are children forms. thank u.

    nobody help you... you have to help you yourself and this is success way.

    D C 3 Replies Last reply
    0
    • M mr mohsen

      hi friends i have a question about object oriented(class inheritance) i have a windows application with c# that in this application i have 2 forms. these 2 forms have few methods i show you below. ========> form1 public partial class form1:Form { public form1() { InitializeComponent(); } public void change_value_label(string new_value) { lbl.Text=new_value;//this label defined as private controll for this form } } =========>form2 public partial class form2:Form { public form2() { InitializeComponent(); } private void subject_Load(object sender, EventArgs e) { //in this area code i want to write a code that call change_value_label method of form1 , but i can't // if i create a new object of form1 then i can call the method but with this way i cannot change the value of the label on form1 //and if i declare change_value_label method on form1 as static method then on the method i cannot access to the label because this controll is not static and i //cannot define the label as static control //please tell me what do i have to do to solve this problem? } } form1 and form2 are showing at te same time because this two forms are children forms. thank u.

      nobody help you... you have to help you yourself and this is success way.

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      I'm not sure what this has to do with inheritance - both forms are inheriting from System.Windows.Forms.Form Anyway, I answered a similar question a few minutes ago here[^]. If both forms are child forms then you may need to use events as well.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

      1 Reply Last reply
      0
      • M mr mohsen

        hi friends i have a question about object oriented(class inheritance) i have a windows application with c# that in this application i have 2 forms. these 2 forms have few methods i show you below. ========> form1 public partial class form1:Form { public form1() { InitializeComponent(); } public void change_value_label(string new_value) { lbl.Text=new_value;//this label defined as private controll for this form } } =========>form2 public partial class form2:Form { public form2() { InitializeComponent(); } private void subject_Load(object sender, EventArgs e) { //in this area code i want to write a code that call change_value_label method of form1 , but i can't // if i create a new object of form1 then i can call the method but with this way i cannot change the value of the label on form1 //and if i declare change_value_label method on form1 as static method then on the method i cannot access to the label because this controll is not static and i //cannot define the label as static control //please tell me what do i have to do to solve this problem? } } form1 and form2 are showing at te same time because this two forms are children forms. thank u.

        nobody help you... you have to help you yourself and this is success way.

        D Offline
        D Offline
        DaveyM69
        wrote on last edited by
        #3

        Colin[^] has a good article on his blog here[^]

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

        1 Reply Last reply
        0
        • M mr mohsen

          hi friends i have a question about object oriented(class inheritance) i have a windows application with c# that in this application i have 2 forms. these 2 forms have few methods i show you below. ========> form1 public partial class form1:Form { public form1() { InitializeComponent(); } public void change_value_label(string new_value) { lbl.Text=new_value;//this label defined as private controll for this form } } =========>form2 public partial class form2:Form { public form2() { InitializeComponent(); } private void subject_Load(object sender, EventArgs e) { //in this area code i want to write a code that call change_value_label method of form1 , but i can't // if i create a new object of form1 then i can call the method but with this way i cannot change the value of the label on form1 //and if i declare change_value_label method on form1 as static method then on the method i cannot access to the label because this controll is not static and i //cannot define the label as static control //please tell me what do i have to do to solve this problem? } } form1 and form2 are showing at te same time because this two forms are children forms. thank u.

          nobody help you... you have to help you yourself and this is success way.

          C Offline
          C Offline
          CodingYoshi
          wrote on last edited by
          #4

          Add a handler for the load event of form2 in form1 and do whatever you need to do. This is the easiest solution and it is OO as well. To do so, create a method or property in form1 and send it the instance of form2. Then within form2 create an event handler for the load event of form1 and do whatever you need to--change the label.

          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