I am creating a stream application. I started using the GUI (Announce: Form) as a separate thread.
This window will be very minimalistic with one input field and possibly with a button. In another thread, Tcp Client will be launched, and when it receives information from TcpServer, it should pass what falls into this input field and show gui (and the topmost windows). After a couple of seconds, gui should hide and wait for another tcp msg and so on.
public void setTextBox(string varText) {
if (InvokeRequired) {
textBox.BeginInvoke(new textBoxCallBack(setTextBox), new object[] {varText});
} else {
textBox.Text = varText;
}
}
This code is used to populate a text field from a Tcp stream. The only problem now is to display the window and hide it. I tried many solutions and always something went wrong. How:
private void windowStateChange(string varState) {
if (InvokeRequired) {
Invoke(new WindowStateChangeCallBack(windowStateChange), new object[] {varState});
} else {
if (varState == "Hide") {
} else {
}
}
}
public void windowStateChangeDiffrent(FormWindowState varState) {
if (InvokeRequired) {
Invoke(new WindowStateChangeCallBack(windowStateChange), new object[] {varState});
} else {
WindowState = varState;
TopMost = varState != FormWindowState.Minimized;
}
}
What would be the best way to do this (and faster, in time)?
Answer 1, which seems to work:
private static void windowStateChange(string varState) {
if (mainAnnounceWindow.InvokeRequired) {
mainAnnounceWindow.BeginInvoke(new StateCallBack(windowStateChange), new object[] {varState});
} else {
if (varState == "Hide") {
mainAnnounceWindow.Hide();
mainAnnounceWindow.TopMost = false;
} else {
mainAnnounceWindow.Show();
mainAnnounceWindow.TopMost = true;
}
}
}
Is there anything bad about this?