kenlim

kenlim

  • NA
  • 1
  • 0

Problem in adding objects in c# window application

Aug 8 2004 11:06 AM
Hi, I had encounted many problems in writing window applications in C#, so I just try to set a simple question : i. Set up a main form with a textBox. ii. Define MyClass to return a string, Create my own object A and show the string in the textBox while I change the text content of textBox. It seems to be a simple job but I can't get it go perfectly. Please advise me : 1. Where is the best place to put the definition MyClass ? 2. Where is the best place to create the object A ? Thanks for anyone who can give me a hand! ken My complete code is listed as below but new created object A was not recognised: /* * Created by SharpDevelop. * User: ken5 * Date: 8/8/2004 * Time: 22:14 * * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; using System.Windows.Forms; namespace DefaultNamespace { // class definition of MyClass : public class MyClass { public string MyText() { return "abc" ; } } /// /// Description of MainForm. /// public class MainForm : System.Windows.Forms.Form { private System.Windows.Forms.TextBox textBox1; public MainForm() { // // The InitializeComponent() call is required for Windows Forms designer support. // InitializeComponent(); // // TODO: Add constructor code after the InitializeComponent() call. // // Create Object A of MyClass MyClass A = new MyClass(); } [STAThread] public static void Main(string[] args) { Application.Run(new MainForm()); } #region Windows Forms Designer generated code /// /// This method is required for Windows Forms designer support. /// Do not change the method contents inside the source code editor. The Forms designer might /// not be able to load this method if it was changed manually. /// private void InitializeComponent() { this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(160, 56); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(104, 22); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; this.textBox1.TextChanged += new System.EventHandler(this.TextBox1TextChanged); // // MainForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 15); this.ClientSize = new System.Drawing.Size(292, 266); this.Controls.Add(this.textBox1); this.Name = "MainForm"; this.Text = "MainForm"; this.ResumeLayout(false); } #endregion void TextBox1TextChanged(object sender, System.EventArgs e) { // Make use of MyClass textBox1.Text = A.MyText(); } } }

Answers (1)