Use of External Classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel EXBN
    New Member
    • Mar 2012
    • 7

    Use of External Classes

    I have this code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using WindowsFormsApplication1;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void buttonClicked(object sender, EventArgs e)
            {
                Print PrintIT = new Print();
                PrintIT.PrintTo();
            }
    
        }
    }
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using WindowsFormsApplication1;
    
    namespace WindowsFormsApplication1
    {
        class Print : Form1
        {
            public void PrintTo()
            {
                richTextBox1.Text += "aaa";
            }
        }
    }


    I cannot figure out why "aaa" is not printed. Why is that?
    No errors, all compiles fine.

    Thanks!
  • LittleDong
    New Member
    • Mar 2012
    • 11

    #2
    I don't think you could build successfully.
    I did like the following and it works.
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
     
    
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Class1 a = new Class1();
                a.PrintTo(textBox1);
                
            }
        }
         
    }
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication1
    {
        class Class1 :Form1
        {
             public void PrintTo(TextBox TBX)
         {
             TBX.Text += "aaa";
           }
    
        }
    }

    Comment

    • Daniel EXBN
      New Member
      • Mar 2012
      • 7

      #3
      Originally posted by LittleDong
      I don't think you could build successfully.
      I did like the following and it works.
      Code:
      using System;
      using System.Collections.Generic;
      using System.ComponentModel;
      using System.Data;
      using System.Drawing;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      
      namespace WindowsFormsApplication1
      {
       
      
          public partial class Form1 : Form
          {
              public Form1()
              {
                  InitializeComponent();
              }
      
              private void button1_Click(object sender, EventArgs e)
              {
                  Class1 a = new Class1();
                  a.PrintTo(textBox1);
                  
              }
          }
           
      }
      Code:
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Windows.Forms;
      
      namespace WindowsFormsApplication1
      {
          class Class1 :Form1
          {
               public void PrintTo(TextBox TBX)
           {
               TBX.Text += "aaa";
             }
      
          }
      }
      Thank You!!!!!!!!!!!! !

      Comment

      Working...