Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Dc Mass - ChatForm.cs

ChatForm.cs

Caricato da:
Scarica il programma completo

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6.  
  7. namespace SaTaNaDcMaSS
  8. {
  9.         /// <summary>
  10.         /// Summary description for ChatForm.
  11.         /// </summary>
  12.         public class ChatForm : System.Windows.Forms.Form
  13.         {
  14.                 private System.Windows.Forms.RichTextBox richTextBox1;
  15.                 private System.Windows.Forms.TextBox textBox1;
  16.                 private System.Windows.Forms.Label label1;
  17.                 private ListBox l;
  18.                 private bool invio=false;
  19.                 private string nick = DcUser.GetNick();
  20.                 /// <summary>
  21.                 /// Required designer variable.
  22.                 /// </summary>
  23.                 private System.ComponentModel.Container components = null;
  24.  
  25.                 public ChatForm(ListBox l)
  26.                 {
  27.                         //
  28.                         // Required for Windows Form Designer support
  29.                         //
  30.                         InitializeComponent();
  31.                         this.l=l;
  32.                         this.Text=" Þv† ¢hå†: "+l.SelectedItem.ToString();
  33.                         DcUser.SetRichTextBox(richTextBox1);
  34.                         DcUser.SetPvtUser(l.SelectedItem.ToString());
  35.                 }
  36.  
  37.                 /// <summary>
  38.                 /// Clean up any resources being used.
  39.                 /// </summary>
  40.                 protected override void Dispose(bool disposing)
  41.                 {
  42.                         if( disposing )
  43.                         {
  44.                                 if(components != null)
  45.                                 {
  46.                                         components.Dispose();
  47.                                 }
  48.                         }
  49.                         base.Dispose( disposing );
  50.                 }
  51.  
  52.                 #region Windows Form Designer generated code
  53.                 /// <summary>
  54.                 /// Required method for Designer support - do not modify
  55.                 /// the contents of this method with the code editor.
  56.                 /// </summary>
  57.                 private void InitializeComponent()
  58.                 {
  59.                         this.richTextBox1 = new System.Windows.Forms.RichTextBox();
  60.                         this.textBox1 = new System.Windows.Forms.TextBox();
  61.                         this.label1 = new System.Windows.Forms.Label();
  62.                         this.SuspendLayout();
  63.                         //
  64.                         // richTextBox1
  65.                         //
  66.                         this.richTextBox1.HideSelection = false;
  67.                         this.richTextBox1.Location = new System.Drawing.Point(8, 8);
  68.                         this.richTextBox1.Name = "richTextBox1";
  69.                         this.richTextBox1.ReadOnly = true;
  70.                         this.richTextBox1.Size = new System.Drawing.Size(280, 176);
  71.                         this.richTextBox1.TabIndex = 0;
  72.                         this.richTextBox1.Text = "";
  73.                         //
  74.                         // textBox1
  75.                         //
  76.                         this.textBox1.Location = new System.Drawing.Point(8, 208);
  77.                         this.textBox1.Multiline = true;
  78.                         this.textBox1.Name = "textBox1";
  79.                         this.textBox1.Size = new System.Drawing.Size(280, 20);
  80.                         this.textBox1.TabIndex = 1;
  81.                         this.textBox1.Text = "";
  82.                         this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox1_KeyPress);
  83.                         this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
  84.                         //
  85.                         // label1
  86.                         //
  87.                         this.label1.Location = new System.Drawing.Point(8, 192);
  88.                         this.label1.Name = "label1";
  89.                         this.label1.Size = new System.Drawing.Size(280, 16);
  90.                         this.label1.TabIndex = 2;
  91.                         this.label1.Text = "Messaggio";
  92.                         //
  93.                         // ChatForm
  94.                         //
  95.                         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  96.                         this.ClientSize = new System.Drawing.Size(296, 238);
  97.                         this.Controls.Add(this.label1);
  98.                         this.Controls.Add(this.textBox1);
  99.                         this.Controls.Add(this.richTextBox1);
  100.                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
  101.                         this.Name = "ChatForm";
  102.                         this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  103.                         this.Text = " Þv† ¢hå†";
  104.                         this.Load += new System.EventHandler(this.ChatForm_Load);
  105.                         this.ResumeLayout(false);
  106.  
  107.                 }
  108.                 #endregion
  109.  
  110.                 private void textBox1_TextChanged(object sender, System.EventArgs e)
  111.                 {
  112.                
  113.                 }
  114.  
  115.                 private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
  116.                 {
  117.                         if(DcUser.GetSocket().Connected)
  118.                         {
  119.                                 char ch=e.KeyChar;
  120.                                 if(invio)
  121.                                 {
  122.                                         textBox1.Text="";
  123.                                         invio=false;
  124.                                 }
  125.                                 if (ch==Convert.ToChar("\r"))
  126.                                 {
  127.                                         if(textBox1.Text!="")
  128.                                         {
  129.                                                 if(invio)
  130.                                                 {
  131.                                                         textBox1.Text="";
  132.                                                         invio=false;
  133.                                                 }
  134.                                                 string ore = Convert.ToString(DateTime.Now.TimeOfDay);
  135.                                                 ore=ore.Substring(0,5);
  136.                                                 string to = l.SelectedItem.ToString();
  137.                                                 DcUser.GetSocket().Send(System.Text.Encoding.Default.GetBytes("$To: "+to+" From: "+nick+" $<"+nick+"> "+textBox1.Text+"|"));
  138.                                                 richTextBox1.AppendText("["+ore+"] <"+nick+"> "+textBox1.Text+"\n");
  139.                                                 textBox1.Text="";
  140.                                                 invio=true;
  141.                                         }
  142.                                         else
  143.                                         {
  144.                                                 MessageBox.Show("Inserisci un messaggio!","Errore",MessageBoxButtons.OK,MessageBoxIcon.Error);
  145.                                         }                              
  146.                                 }
  147.                         }
  148.                 }
  149.  
  150.                 private void ChatForm_Load(object sender, System.EventArgs e)
  151.                 {
  152.                
  153.                 }
  154.         }
  155. }