我写了这段代码:
public partial class MainWindow : MetroWindow
{
private static byte[] _buffer = new byte[1024];
private static List<Socket> _clientSockets = new List<Socket>();
private static Socket _serverSocket = new Socket
(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
SetupServer();
}
public void changeColorButton()
{
var custom = new BrushConverter();
testButton.Background = (Brush)custom.ConvertFrom("#FF00D400");
}
private static void SetupServer()
{
_serverSocket.Bind(new IPEndPoint(IPAddress.Any, 100));
MessageBox.Show("Server ONLINE");
_serverSocket.Listen(5);
_serverSocket.BeginAccept(new AsyncCallback(AcceptCallBack), null);
}
private static void AcceptCallBack(IAsyncResult AR)
{
Socket socket = _serverSocket.EndAccept(AR);
_clientSockets.Add(socket);
-----<triggers the changeColorButton() here>---
s.Add(socket);
socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallBack), socket);
_serverSocket.BeginAccept(new AsyncCallback(AcceptCallBack), null);
}
}
它接受将尝试连接到服务器的客户端。我还有一个测试按钮。我试图在客户端尝试连接服务器时更改按钮的颜色。
我尝试使用以下代码调用changeColorButton():
MainWindow m = new MainWindow();
m.changeColorButton;
但似乎我在这个问题上遇到了错误。有关如何在尝试连接到服务器的客户端时如何更改按钮颜色的任何建议?谢谢。 :)
答案 0 :(得分:0)
尝试ConvertFromString
而不是ConvertFrom