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. Communication with controls between classes

Communication with controls between classes

Scheduled Pinned Locked Moved C#
csharpjavascriptgraphicsdockerhelp
4 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.
  • D Offline
    D Offline
    DJNokturnal
    wrote on last edited by
    #1

    Hey guys... first I just want to praise The Code Project and everyone on here for basically teaching me the basics of C#. I have a web background and this is the first language I have learned coming off my javascript and vbscript web knowledge. I am sure this question has a very simple answer, but that is an answer I cannot figure out! :) Here it is... I have dummied down my problem into the following code examples. I have a very basic program that takes one richtext field and copies the content into another. I am doing so by calling a method in a separate class that accomplishes the copying of text. Form1.cs: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace TestApp { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; public System.Windows.Forms.RichTextBox txtFromSecondClass; public System.Windows.Forms.RichTextBox txtToSecondClass; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.txtFromSecondClass = new System.Windows.Forms.RichTextBox(); this.label1 = new System.Windows.Forms.Label(); this.txtToSecondClass = new System.Windows.Forms.RichTextBox(); this.label2 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtFromSecondClass // this.txtFromSecondClass.Location = new System.Drawing.Point(8, 200); this.txtFromSecondClass.Name = "txtFromSecondClass"; this.t

    N 1 Reply Last reply
    0
    • D DJNokturnal

      Hey guys... first I just want to praise The Code Project and everyone on here for basically teaching me the basics of C#. I have a web background and this is the first language I have learned coming off my javascript and vbscript web knowledge. I am sure this question has a very simple answer, but that is an answer I cannot figure out! :) Here it is... I have dummied down my problem into the following code examples. I have a very basic program that takes one richtext field and copies the content into another. I am doing so by calling a method in a separate class that accomplishes the copying of text. Form1.cs: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace TestApp { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; public System.Windows.Forms.RichTextBox txtFromSecondClass; public System.Windows.Forms.RichTextBox txtToSecondClass; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button1; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.txtFromSecondClass = new System.Windows.Forms.RichTextBox(); this.label1 = new System.Windows.Forms.Label(); this.txtToSecondClass = new System.Windows.Forms.RichTextBox(); this.label2 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtFromSecondClass // this.txtFromSecondClass.Location = new System.Drawing.Point(8, 200); this.txtFromSecondClass.Name = "txtFromSecondClass"; this.t

      N Offline
      N Offline
      Nicholas Cardi
      wrote on last edited by
      #2

      your problem is that you are creating a new instance of form1. You need to pass in the existing instance of form1 transfertext to take the existing instance public static string transfertext(System.Windows.Forms.Form x) { return x.txtFromSecondClass.Text; } usage string value = SecondClass.transfertext(this); best of luck Forever Developing

      D 2 Replies Last reply
      0
      • N Nicholas Cardi

        your problem is that you are creating a new instance of form1. You need to pass in the existing instance of form1 transfertext to take the existing instance public static string transfertext(System.Windows.Forms.Form x) { return x.txtFromSecondClass.Text; } usage string value = SecondClass.transfertext(this); best of luck Forever Developing

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

        Hey thanks for the reply! ... and here is the but hehehe ... Can you treat me like a moron, and show me the rewritten methods for each class? I just can't wrap my mind around this... :((

        1 Reply Last reply
        0
        • N Nicholas Cardi

          your problem is that you are creating a new instance of form1. You need to pass in the existing instance of form1 transfertext to take the existing instance public static string transfertext(System.Windows.Forms.Form x) { return x.txtFromSecondClass.Text; } usage string value = SecondClass.transfertext(this); best of luck Forever Developing

          D Offline
          D Offline
          DJNokturnal
          wrote on last edited by
          #4

          ..\..\..\SecondClass.cs(12): 'System.Windows.Forms.Form' does not contain a definition for 'textFromSecondClass' That is what I get when I try to use your code. I guess I have some reading to do. Thanks anyway.

          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