Server - client for intepreting string and show it as image in main form
Hi,
I am a beginner, and trying to call an image inside a form.
So basically, I have done a simple WPF application in which if I press a button, I will managed to show an image in my main form. So, the code is below :
private void btnAddMore_Click(object sender, RoutedEventArgs e)
{
FunctImage();
}
public void FunctImage()
{
System.Windows.Controls.Image img = new Image();
img.Source = new BitmapImage(new Uri(@"C:\bla.jpg"));
img.Width = 200;
Content = img;
}
I tried to implement this function in a server (one window form with a button). And if I press a button, the client would start listening for the client. If the client send a string (e.g. "send"), the server would accept this string, and call the FunctImage above. I have debugged it, I received the "send" string, however when the FunctImage is called, my main form is hang. I tried to go around with it, but until know, it does not work. So, the code is below
string newTest = Encoding.ASCII.GetString(data, 0, recv);
if (newTest.Equals("send"))
{
//if I show another form outside the main form, it work just fine.E.G:
//MessageBox.Show("String received"); //this Message box is shown outside //the main form sucessfully, after server received the string from client
//if I call the FunctImage, the main forms can not show the image,hang..
FunctImage();
}
ns.Write(data, 0, recv);
}
ns.Close();
client.Close();
newsock.Stop();
Thank you for the guidance.. Any small tips will be very useful.
reza.adinata
Junior Poster in Training
54 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Yes, C:\bla.jpg is there.
Content is default object of the main window
reza.adinata
Junior Poster in Training
54 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
Is Content a form?
If not, what control type is it?
nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
it is a default function to call the image. However *very unfortunate* I can not find any adequate explanation for "content". For my problem, I think it is solvable by using delegates. There is a problem with updating the UI from other thread, so I am currently trying to understand this .. I will dig deeper into this. Thank you for all of your responses, appreciate it so much!..
reza.adinata
Junior Poster in Training
54 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0