Click here to Skip to main content
16,010,876 members
Home / Discussions / C#
   

C#

 
GeneralGetting a list of installed appliactions Pin
leifm10-Aug-04 10:20
leifm10-Aug-04 10:20 
GeneralRe: Getting a list of installed appliactions Pin
Nick Parker10-Aug-04 10:44
protectorNick Parker10-Aug-04 10:44 
GeneralRe: Getting a list of installed appliactions Pin
Heath Stewart10-Aug-04 11:33
protectorHeath Stewart10-Aug-04 11:33 
GeneralA problem in DataGrid Pin
ImanMahmoud10-Aug-04 9:25
ImanMahmoud10-Aug-04 9:25 
GeneralComboboxes and Tooltips Pin
fozzwald10-Aug-04 9:10
fozzwald10-Aug-04 9:10 
GeneralHook up a static object to the Property Grid Pin
matthias s.10-Aug-04 8:54
matthias s.10-Aug-04 8:54 
GeneralRe: Hook up a static object to the Property Grid Pin
Nick Parker10-Aug-04 10:39
protectorNick Parker10-Aug-04 10:39 
GeneralNewLine Hell... Pin
Korjiro10-Aug-04 8:27
Korjiro10-Aug-04 8:27 
New line is really giving me a tough time...



i have a text box, and it displays the message to another text box.... but when i do Environment.Newline or \r\n, nothing happens....


here is my code

<br />
<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 />
using System.Net.Sockets;<br />
using System.Net;<br />
<br />
namespace WindowsApplication1<br />
{<br />
	/// <summary><br />
	/// Summary description for Form1.<br />
	/// </summary><br />
	public class Form1 : System.Windows.Forms.Form<br />
	{<br />
		private System.Windows.Forms.MainMenu mainMenu1;<br />
		private System.Windows.Forms.MenuItem menuItem1;<br />
		private System.Windows.Forms.MenuItem menuItem2;<br />
		private System.Windows.Forms.TextBox textBox1;<br />
		private System.Windows.Forms.TextBox textBox2;<br />
		private System.Windows.Forms.TextBox textBox3;<br />
		private System.Windows.Forms.Label label2;<br />
		private System.Windows.Forms.Label label3;<br />
		private System.Windows.Forms.Label label4;<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 />
		#region Disposing<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 />
		#endregion<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.mainMenu1 = new System.Windows.Forms.MainMenu();<br />
			this.menuItem1 = new System.Windows.Forms.MenuItem();<br />
			this.menuItem2 = new System.Windows.Forms.MenuItem();<br />
			this.textBox1 = new System.Windows.Forms.TextBox();<br />
			this.textBox2 = new System.Windows.Forms.TextBox();<br />
			this.textBox3 = new System.Windows.Forms.TextBox();<br />
			this.label2 = new System.Windows.Forms.Label();<br />
			this.label3 = new System.Windows.Forms.Label();<br />
			this.label4 = new System.Windows.Forms.Label();<br />
			this.button1 = new System.Windows.Forms.Button();<br />
			this.SuspendLayout();<br />
			// <br />
			// mainMenu1<br />
			// <br />
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
																					  this.menuItem1});<br />
			// <br />
			// menuItem1<br />
			// <br />
			this.menuItem1.Index = 0;<br />
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {<br />
																					  this.menuItem2});<br />
			this.menuItem1.Text = "File";<br />
			// <br />
			// menuItem2<br />
			// <br />
			this.menuItem2.Index = 0;<br />
			this.menuItem2.Text = "Quit";<br />
			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);<br />
			// <br />
			// textBox1<br />
			// <br />
			this.textBox1.AutoSize = false;<br />
			this.textBox1.BackColor = System.Drawing.SystemColors.WindowText;<br />
			this.textBox1.ForeColor = System.Drawing.Color.Honeydew;<br />
			this.textBox1.Location = new System.Drawing.Point(16, 24);<br />
			this.textBox1.Name = "textBox1";<br />
			this.textBox1.ReadOnly = true;<br />
			this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;<br />
			this.textBox1.Size = new System.Drawing.Size(328, 128);<br />
			this.textBox1.TabIndex = 0;<br />
			this.textBox1.Text = "";<br />
			// <br />
			// textBox2<br />
			// <br />
			this.textBox2.AutoSize = false;<br />
			this.textBox2.BackColor = System.Drawing.SystemColors.WindowText;<br />
			this.textBox2.ForeColor = System.Drawing.Color.MintCream;<br />
			this.textBox2.Location = new System.Drawing.Point(384, 24);<br />
			this.textBox2.Name = "textBox2";<br />
			this.textBox2.ReadOnly = true;<br />
			this.textBox2.Size = new System.Drawing.Size(80, 128);<br />
			this.textBox2.TabIndex = 1;<br />
			this.textBox2.Text = "";<br />
			// <br />
			// textBox3<br />
			// <br />
			this.textBox3.AcceptsTab = true;<br />
			this.textBox3.AutoSize = false;<br />
			this.textBox3.BackColor = System.Drawing.SystemColors.WindowFrame;<br />
			this.textBox3.ForeColor = System.Drawing.Color.White;<br />
			this.textBox3.Location = new System.Drawing.Point(16, 184);<br />
			this.textBox3.Name = "textBox3";<br />
			this.textBox3.Size = new System.Drawing.Size(384, 40);<br />
			this.textBox3.TabIndex = 2;<br />
			this.textBox3.Text = "";<br />
			this.textBox3.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox3_KeyPressed);<br />
			this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);<br />
			// <br />
			// label2<br />
			// <br />
			this.label2.Font = new System.Drawing.Font("Eurostile", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
			this.label2.ForeColor = System.Drawing.Color.Lime;<br />
			this.label2.Location = new System.Drawing.Point(16, 8);<br />
			this.label2.Name = "label2";<br />
			this.label2.Size = new System.Drawing.Size(136, 16);<br />
			this.label2.TabIndex = 4;<br />
			this.label2.Text = "Message Display";<br />
			// <br />
			// label3<br />
			// <br />
			this.label3.BackColor = System.Drawing.Color.Black;<br />
			this.label3.Font = new System.Drawing.Font("Eurostile", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
			this.label3.ForeColor = System.Drawing.Color.Lime;<br />
			this.label3.Location = new System.Drawing.Point(16, 168);<br />
			this.label3.Name = "label3";<br />
			this.label3.Size = new System.Drawing.Size(128, 16);<br />
			this.label3.TabIndex = 5;<br />
			this.label3.Text = "Current Message";<br />
			// <br />
			// label4<br />
			// <br />
			this.label4.Font = new System.Drawing.Font("Eurostile", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
			this.label4.ForeColor = System.Drawing.Color.Lime;<br />
			this.label4.Location = new System.Drawing.Point(376, 8);<br />
			this.label4.Name = "label4";<br />
			this.label4.Size = new System.Drawing.Size(104, 16);<br />
			this.label4.TabIndex = 6;<br />
			this.label4.Text = "Clients Online";<br />
			this.label4.Click += new System.EventHandler(this.label4_Click);<br />
			// <br />
			// button1<br />
			// <br />
			this.button1.BackColor = System.Drawing.Color.Black;<br />
			this.button1.Font = new System.Drawing.Font("Eurostile", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));<br />
			this.button1.ForeColor = System.Drawing.Color.Lime;<br />
			this.button1.Location = new System.Drawing.Point(264, 240);<br />
			this.button1.Name = "button1";<br />
			this.button1.Size = new System.Drawing.Size(88, 24);<br />
			this.button1.TabIndex = 7;<br />
			this.button1.Text = "Connect";<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.BackColor = System.Drawing.SystemColors.ControlText;<br />
			this.ClientSize = new System.Drawing.Size(488, 273);<br />
			this.Controls.Add(this.button1);<br />
			this.Controls.Add(this.label4);<br />
			this.Controls.Add(this.label3);<br />
			this.Controls.Add(this.label2);<br />
			this.Controls.Add(this.textBox3);<br />
			this.Controls.Add(this.textBox2);<br />
			this.Controls.Add(this.textBox1);<br />
			this.Menu = this.mainMenu1;<br />
			this.Name = "Form1";<br />
			this.Text = "ChatteX v1.0";<br />
			this.ResumeLayout(false);<br />
<br />
		}<br />
		#endregion<br />
	<br />
		#region Client Variables...<br />
		byte[] m_dataBuffer = new byte [10];<br />
		IAsyncResult m_result;<br />
		public AsyncCallback m_pfnCallBack ;<br />
		public Socket m_clientSocket;<br />
		#endregion<br />
	<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		#region AppMain()<br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new Form1());<br />
		}<br />
		#endregion<br />
<br />
		#region Program Functions<br />
		public void SetText(TextBox m, TextBox d)<br />
		{<br />
			<br />
			string buffer =Environment.NewLine;<br />
<br />
			buffer =m.Text+Environment.NewLine;<br />
			d.Text += buffer;<br />
			m.Text ="";<br />
		}<br />
<br />
<br />
		public void WaitForData()<br />
		{<br />
			try<br />
			{<br />
				if  ( m_pfnCallBack == null ) <br />
				{<br />
					m_pfnCallBack = new AsyncCallback (OnDataReceived);<br />
				}<br />
				SocketPacket theSocPkt = new SocketPacket ();<br />
				theSocPkt.thisSocket = m_clientSocket;<br />
				// Start listening to the data asynchronously<br />
				m_result = m_clientSocket.BeginReceive (theSocPkt.dataBuffer,<br />
					0, theSocPkt.dataBuffer.Length,<br />
					SocketFlags.None, <br />
					m_pfnCallBack, <br />
					theSocPkt);<br />
			}<br />
			catch(SocketException se)<br />
			{<br />
				MessageBox.Show (se.Message );<br />
			}<br />
<br />
		}<br />
		public class SocketPacket<br />
		{<br />
			public System.Net.Sockets.Socket thisSocket;<br />
			public byte[] dataBuffer = new byte[1];<br />
		}<br />
<br />
		public  void OnDataReceived(IAsyncResult asyn)<br />
		{<br />
			try<br />
			{<br />
				SocketPacket theSockId = (SocketPacket)asyn.AsyncState ;<br />
				int iRx  = theSockId.thisSocket.EndReceive (asyn);<br />
				char[] chars = new char[iRx +  1];<br />
				System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();<br />
				int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);<br />
				System.String szData = new System.String(chars);<br />
				textBox1.Text += szData;<br />
				WaitForData();<br />
			}<br />
			catch (ObjectDisposedException )<br />
			{<br />
				System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");<br />
			}<br />
			catch(SocketException se)<br />
			{<br />
				MessageBox.Show (se.Message );<br />
			}<br />
		}	<br />
		<br />
<br />
		#endregion<br />
<br />
		#region Event Handlers<br />
		private void menuItem2_Click(object sender, System.EventArgs e)<br />
		{<br />
			if(MessageBox.Show("Are you sure you want to quit?","Exit Code:101",<br />
				MessageBoxButtons.OKCancel,MessageBoxIcon.Warning)== DialogResult.OK)<br />
			{<br />
				Application.Exit();<br />
			}<br />
		}<br />
<br />
		private void textBox3_TextChanged(object sender, System.EventArgs e)<br />
		{<br />
		}  <br />
<br />
		private void textBox3_KeyPressed(object sender, KeyPressEventArgs e)<br />
		{<br />
			if(e.KeyChar == (char)13)<br />
			{	<br />
				SetText(textBox3,textBox1);<br />
			}<br />
		}<br />
		private void label4_Click(object sender, System.EventArgs e)<br />
		{<br />
		<br />
		}<br />
<br />
<br />
		<br />
		private void button1_Click(object sender, System.EventArgs e)<br />
		{<br />
			textBox1.Text +="Connecting to server....\r\n";<br />
<br />
			try<br />
			{<br />
				m_clientSocket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );<br />
				IPAddress ip = IPAddress.Parse("65.96.57.169");<br />
				int iPortNo = 2486;<br />
				IPEndPoint ipEnd = new IPEndPoint (ip,iPortNo);<br />
				m_clientSocket.Connect ( ipEnd );<br />
				<br />
				if(m_clientSocket.Connected) <br />
				{<br />
					textBox1.Text+="Connection Aquired...\r\n";<br />
					WaitForData();<br />
				}<br />
			}<br />
			catch(SocketException se)<br />
			{<br />
				MessageBox.Show (se.ToString(),"Server is down",MessageBoxButtons.OKCancel);<br />
			}		<br />
		#endregion	<br />
		}			<br />
	}<br />
		<br />
		<br />
	}	<br />
<br />
<br />
<br />

GeneralRe: NewLine Hell... Pin
Stefan Troschuetz10-Aug-04 9:26
Stefan Troschuetz10-Aug-04 9:26 
GeneralRe: NewLine Hell... Pin
Korjiro10-Aug-04 11:00
Korjiro10-Aug-04 11:00 
GeneralExecuteNonQuery Pin
Member 84960810-Aug-04 7:42
Member 84960810-Aug-04 7:42 
GeneralRe: ExecuteNonQuery Pin
Heath Stewart10-Aug-04 11:39
protectorHeath Stewart10-Aug-04 11:39 
GeneralRegistry Problem..! Pin
QzRz10-Aug-04 7:22
QzRz10-Aug-04 7:22 
GeneralRe: Registry Problem..! Pin
Nick Parker10-Aug-04 7:40
protectorNick Parker10-Aug-04 7:40 
Questionhow do get permission to send an email from ASP.net? Pin
spazzman10-Aug-04 7:15
spazzman10-Aug-04 7:15 
AnswerRe: how do get permission to send an email from ASP.net? Pin
Nick Parker10-Aug-04 7:28
protectorNick Parker10-Aug-04 7:28 
QuestionHow to operate registry of WinCE Pin
wk_vigorous10-Aug-04 6:48
wk_vigorous10-Aug-04 6:48 
AnswerRe: How to operate registry of WinCE Pin
Nick Parker10-Aug-04 7:24
protectorNick Parker10-Aug-04 7:24 
GeneralA problem in DataGrid Pin
Anonymous10-Aug-04 4:50
Anonymous10-Aug-04 4:50 
GeneralRe: A problem in DataGrid Pin
Nick Parker10-Aug-04 6:11
protectorNick Parker10-Aug-04 6:11 
Generalavoiding double invoking Pin
Stephan Wright10-Aug-04 3:25
Stephan Wright10-Aug-04 3:25 
GeneralRe: avoiding double invoking Pin
Nick Parker10-Aug-04 3:49
protectorNick Parker10-Aug-04 3:49 
GeneralRe: avoiding double invoking Pin
Stephan Wright10-Aug-04 4:02
Stephan Wright10-Aug-04 4:02 
GeneralRe: avoiding double invoking Pin
Nick Parker10-Aug-04 4:21
protectorNick Parker10-Aug-04 4:21 
GeneralRe: avoiding double invoking Pin
Stephan Wright10-Aug-04 22:04
Stephan Wright10-Aug-04 22:04 

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.