Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
QuestionString.Replace...does it even work? Pin
FocusedWolf15-Apr-05 11:23
FocusedWolf15-Apr-05 11:23 
AnswerRe: String.Replace...does it even work? Pin
afinnell15-Apr-05 11:33
afinnell15-Apr-05 11:33 
GeneralRe: String.Replace...does it even work? Pin
FocusedWolf17-Apr-05 16:35
FocusedWolf17-Apr-05 16:35 
GeneralGetting a DataSet of selected rows in a DataGrid Pin
Member 141845415-Apr-05 10:47
Member 141845415-Apr-05 10:47 
GeneralRe: Getting a DataSet of selected rows in a DataGrid Pin
Member 141845425-Apr-05 6:13
Member 141845425-Apr-05 6:13 
GeneralListView and selectedindex changed event Pin
code_wiz15-Apr-05 10:30
code_wiz15-Apr-05 10:30 
GeneralRe: ListView and selectedindex changed event Pin
afinnell15-Apr-05 11:36
afinnell15-Apr-05 11:36 
GeneralCommunication with controls between classes Pin
DJNokturnal15-Apr-05 10:11
DJNokturnal15-Apr-05 10:11 
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! Smile | :)

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:
<br />
using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
namespace TestApp<br />
{<br />
	/// <summary><br />
	/// Summary description for Form1.<br />
	/// </summary><br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.Label label1;<br />
		public System.Windows.Forms.RichTextBox txtFromSecondClass;<br />
		public System.Windows.Forms.RichTextBox txtToSecondClass;<br />
		private System.Windows.Forms.Label label2;<br />
		private System.Windows.Forms.Button button1;<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
<br />
		public Form1()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
		}<br />
<br />
		/// <summary><br />
		/// Clean up any resources being used.<br />
		/// </summary><br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
			this.txtFromSecondClass = new System.Windows.Forms.RichTextBox();<br />
			this.label1 = new System.Windows.Forms.Label();<br />
			this.txtToSecondClass = new System.Windows.Forms.RichTextBox();<br />
			this.label2 = new System.Windows.Forms.Label();<br />
			this.button1 = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// txtFromSecondClass<br />
			// <br />
			this.txtFromSecondClass.Location = new System.Drawing.Point(8, 200);<br />
			this.txtFromSecondClass.Name = "txtFromSecondClass";<br />
			this.txtFromSecondClass.Size = new System.Drawing.Size(280, 64);<br />
			this.txtFromSecondClass.TabIndex = 0;<br />
			this.txtFromSecondClass.Text = "";<br />
			// <br />
			// label1<br />
			// <br />
			this.label1.Location = new System.Drawing.Point(8, 176);<br />
			this.label1.Name = "label1";<br />
			this.label1.Size = new System.Drawing.Size(272, 16);<br />
			this.label1.TabIndex = 1;<br />
			this.label1.Text = "From SecondClass:";<br />
			// <br />
			// txtToSecondClass<br />
			// <br />
			this.txtToSecondClass.Location = new System.Drawing.Point(8, 32);<br />
			this.txtToSecondClass.Name = "txtToSecondClass";<br />
			this.txtToSecondClass.Size = new System.Drawing.Size(280, 64);<br />
			this.txtToSecondClass.TabIndex = 2;<br />
			this.txtToSecondClass.Text = "";<br />
			// <br />
			// label2<br />
			// <br />
			this.label2.Location = new System.Drawing.Point(8, 8);<br />
			this.label2.Name = "label2";<br />
			this.label2.Size = new System.Drawing.Size(272, 16);<br />
			this.label2.TabIndex = 3;<br />
			this.label2.Text = "Send To SecondClass:";<br />
			this.label2.Click += new System.EventHandler(this.label2_Click);<br />
			// <br />
			// button1<br />
			// <br />
			this.button1.Location = new System.Drawing.Point(24, 120);<br />
			this.button1.Name = "button1";<br />
			this.button1.Size = new System.Drawing.Size(240, 32);<br />
			this.button1.TabIndex = 4;<br />
			this.button1.Text = "Send To Second Class";<br />
			this.button1.Click += new System.EventHandler(this.button1_Click);<br />
			// <br />
			// Form1<br />
			// <br />
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);<br />
			this.ClientSize = new System.Drawing.Size(292, 273);<br />
			this.Controls.Add(this.button1);<br />
			this.Controls.Add(this.label2);<br />
			this.Controls.Add(this.txtToSecondClass);<br />
			this.Controls.Add(this.label1);<br />
			this.Controls.Add(this.txtFromSecondClass);<br />
			this.Name = "Form1";<br />
			this.Text = "Form1";<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			SecondClass.transferText(txtToSecondClass.Text);<br />
		}<br />
<br />
		private void label2_Click(object sender, System.EventArgs e)<br />
		{<br />
		<br />
		}<br />
	}<br />
}<br />



SecondClass.cs:

<br />
using System;<br />
<br />
namespace TestApp<br />
{<br />
	/// <summary><br />
	/// Summary description for SecondClass.<br />
	/// </summary><br />
	public class SecondClass<br />
	{<br />
		public static void transferText(string x)<br />
		{<br />
			Form1 formObj = new Form1();<br />
			formObj.txtFromSecondClass.Text = x;<br />
		}<br />
	}<br />
}<br />


Any input would be awesome. Thanks again for such a great site =)

P.S. This isn't an example of the real code I am working on, but does illustrate the problem I have. I know the above project can be very simply accomplished in one class.
GeneralRe: Communication with controls between classes Pin
Nicholas Cardi15-Apr-05 13:34
Nicholas Cardi15-Apr-05 13:34 
GeneralRe: Communication with controls between classes Pin
DJNokturnal15-Apr-05 13:54
DJNokturnal15-Apr-05 13:54 
GeneralRe: Communication with controls between classes Pin
DJNokturnal18-Apr-05 5:40
DJNokturnal18-Apr-05 5:40 
GeneralA list of pairs (string, int) + sorting Pin
domo_15-Apr-05 10:00
domo_15-Apr-05 10:00 
GeneralRe: A list of pairs (string, int) + sorting Pin
afinnell15-Apr-05 11:50
afinnell15-Apr-05 11:50 
GeneralRe: A list of pairs (string, int) + sorting Pin
Nicholas Cardi15-Apr-05 12:15
Nicholas Cardi15-Apr-05 12:15 
GeneralRe: A list of pairs (string, int) + sorting Pin
leppie15-Apr-05 21:24
leppie15-Apr-05 21:24 
GeneralEmbedded User Control Pin
Larsenal15-Apr-05 8:24
Larsenal15-Apr-05 8:24 
GeneralRe: Embedded User Control Pin
Nicholas Cardi15-Apr-05 12:17
Nicholas Cardi15-Apr-05 12:17 
GeneralWindow Service Startup Mode Pin
Hercules0115-Apr-05 7:46
Hercules0115-Apr-05 7:46 
GeneralRe: Window Service Startup Mode Pin
DafeNilesh27-Jan-09 8:10
DafeNilesh27-Jan-09 8:10 
Generalneed help opeing projects Pin
microuser_200015-Apr-05 6:56
microuser_200015-Apr-05 6:56 
GeneralRe: need help opeing projects Pin
Judah Gabriel Himango15-Apr-05 7:00
sponsorJudah Gabriel Himango15-Apr-05 7:00 
GeneralCan't delete BMP file in C# Win App Pin
Khang Nguyen15-Apr-05 6:38
Khang Nguyen15-Apr-05 6:38 
GeneralRe: Can't delete BMP file in C# Win App Pin
Dave Kreskowiak15-Apr-05 7:42
mveDave Kreskowiak15-Apr-05 7:42 
GeneralRe: Can't delete BMP file in C# Win App Pin
Khang Nguyen15-Apr-05 7:50
Khang Nguyen15-Apr-05 7:50 
GeneralRe: Can't delete BMP file in C# Win App Pin
eggie515-Apr-05 20:20
eggie515-Apr-05 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.