示例#1
0
 private void BtnOFD_Click(object sender, EventArgs e)
 {
     using (OpenFileDialog openFileDialog = new OpenFileDialog())
     {
         openFileDialog.Filter = "Image|*.jpg|Arquivo txt|*.txt";
         openFileDialog.Title  = "Selecione uma imagem";
         if (openFileDialog.ShowDialog() == DialogResult.OK)
         {
             ProjetoChat.Mensagem msg = new ProjetoChat.Mensagem(string.Empty, null, nick, DateTime.Now, null);
             if (Path.GetExtension(openFileDialog.FileName).Equals(".jpg"))
             {
                 Image img = Image.FromFile(openFileDialog.FileName);
                 msg.setImage(img);
             }
             if (Path.GetExtension(openFileDialog.FileName).Equals(".txt"))
             {
                 string[] conteudo = FileReadWrite.ReadTextFile(openFileDialog.FileName);
                 msg.setTxt(conteudo);
             }
             byte[] buffer = SerializeMensagem(msg);
             if (buffer.Length >= 102400)
             {
                 MessageBox.Show("Arquivo muito grande, não vai ser possivel fazer a transferencia", "ops...");
             }
             else
             {
                 ClientTCP.SendData(buffer);
             }
         }
     }
 }
示例#2
0
 private void SalvarToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (FolderBrowserDialog fbd = new FolderBrowserDialog())
     {
         if (fbd.ShowDialog() == DialogResult.OK)
         {
             Random rd = new Random();
             FileReadWrite.SaveBinaryFile(fbd.SelectedPath + "\\" + rd.Next() + ".txt", richTextBox1.Lines);
         }
     }
 }