why it's not work?
Yairk_kaufmann
6
Reputation points
I do a chat project and I want to make an option to send a picture so I send the position of the picture and then when you get a position of a picture then a new picture box is created whose picture is equal to the position of the picture I received but I have an error, it's said that it is not a file location
client code:
using SimpleTcp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Socil
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpClient client;
int locY;
private void Form1_Load(object sender, EventArgs e)
{
client = new(txtIP.Text);
client.Events.Connected += Events_ClientConnected;
client.Events.DataReceived += Events_DataReceived;
client.Events.Disconnected += Events_ClientDisconnected;
}
private void Events_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
{
}
private void Events_DataReceived(object sender, DataReceivedEventArgs e)
{
this.Invoke((MethodInvoker)delegate
{
if (Encoding.UTF8.GetString(e.Data).Contains("C:") || Encoding.UTF8.GetString(e.Data).Contains("D:"))
{
string f = Encoding.UTF8.GetString(e.Data);
locY += 51;
PictureBox tb4 = new PictureBox();
tb4.Location = new Point(pictureBox1.Location.X, pictureBox1.Location.Y);
//tb4.Text = $"fraind: {Encoding.UTF8.GetString(e.Data)} {Environment.NewLine}";
tb4.Size = pictureBox1.Size;
tb4.BackColor = pictureBox1.BackColor;
//string t = Encoding.UTF8.GetString(e.Data);
//Image myimage = new Bitmap(@f);
Image myimage = new Bitmap(@Encoding.UTF8.GetString(e.Data));
tb4.BackgroundImage = myimage;
Panel pe4 = new Panel();
pe4.Location = tb4.Location;
pe4.Size = new Size(tb4.Size.Width + 7, tb4.Size.Height + 6);
pe4.BackColor = panel1.BackColor;
pe4.BackgroundImageLayout = panel1.BackgroundImageLayout;
pe4.BackgroundImage = panel1.BackgroundImage;
Controls.Add(tb4);
Controls.Add(pe4);
pe4.Parent = panel4;
tb4.Parent = panel4;
pe4.BringToFront();
tb4.BringToFront();
locY += pe4.Size.Height;
}
if(!Encoding.UTF8.GetString(e.Data).Contains("c:") || !Encoding.UTF8.GetString(e.Data).Contains("d:"))
{
locY += 51;
Label tb = new Label();
tb.Location = new Point(label5.Location.X, locY);
tb.Text = $"fraind: {Encoding.UTF8.GetString(e.Data)} {Environment.NewLine}";
tb.Size = label5.Size;
tb.BackColor = label5.BackColor;
Panel pe = new Panel();
pe.Location = new Point(panel5.Location.X, locY - 8);
pe.Size = panel5.Size;
pe.BackColor = panel5.BackColor;
pe.BackgroundImageLayout = panel5.BackgroundImageLayout;
pe.BackgroundImage = panel5.BackgroundImage;
Controls.Add(tb);
Controls.Add(pe);
pe.Parent = panel4;
tb.Parent = panel4;
pe.BringToFront();
tb.BringToFront();
}
richTextBox1.Text += Encoding.UTF8.GetString(e.Data);
});
}
private void Events_ClientConnected(object sender, ClientConnectedEventArgs e)
{
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
try
{
client.Connect();
button1.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "messege", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnSebd_Click(object sender, EventArgs e)
{
client.Send(txtMessege.Text);
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
openFileDialog1.ShowDialog();
if(result == DialogResult.OK)
{
client.Send(openFileDialog1.FileName);
}
}
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
int n = vScrollBar1.Value;
panel4.Location = new Point(panel4.Location.X,-n);
}
private void button3_Click(object sender, EventArgs e)
{
}
}
}
Server code:
using SimpleTcp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Server
{
public partial class Form1 : Form
{
IList<string> Clients = new List<string>() {};
int h = 0;
public Form1()
{
InitializeComponent();
}
SimpleTcpServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new SimpleTcpServer(txtIP.Text);
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
}
private void btnStart_Click(object sender, EventArgs e)
{
server.Start();
server.Events.ClientConnected += Events_ClientConnected;
server.Events.ClientDisconnected += Events_ClientDisconnected;
server.Events.DataReceived += Events_DataReceived;
btnStart.Enabled = false;
}
private void Events_DataReceived(object sender, DataReceivedEventArgs e)
{
if (h <= Clients.Count + 1)
{
if(Encoding.UTF8.GetString(e.Data).Contains("c:") || Encoding.UTF8.GetString(e.Data).Contains("d:"))
{
for (int i = 0; i < Clients.Count; i++)
{
string f = Encoding.UTF8.GetString(e.Data);
server.Send(Clients[i], @f);
}
}
for (int i = 0; i < Clients.Count; i++)
{
server.Send(Clients[i], $"{e.IpPort}: {Encoding.UTF8.GetString(e.Data)} {Environment.NewLine}");
}
}
else
{
h = 0;
}
//string l = server.GetClients().ToString();
//server.Send(l, $"{e.IpPort}: {Encoding.UTF8.GetString(e.Data)} {Environment.NewLine}");
}
private void Events_ClientDisconnected(object sender, ClientDisconnectedEventArgs e)
{
}
private void Events_ClientConnected(object sender, ClientConnectedEventArgs e)
{
//lstClients.Items.Add(e.IpPort);
Clients.Add(e.IpPort);
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
}
How to fix this?