public static void MessageBoxShow(SendMessageBox packet) { selectIcon(packet.icon); MessageBox.Show(packet.message, packet.title, MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); }
private void SendButton_Click(object sender, EventArgs e) { if (ClientLogic.Connected) { if (SendMessageBox.Text != string.Empty) { DateTime date = DateTime.Now; string message = $"[{date.ToShortTimeString()}] {ClientLogic.Username}: {SendMessageBox.Text}"; CreateRequests.SendMessage(FriendUsernameLable.Text, message); ChatMessageBox.Text += message; ChatMessageBox.Text += "\r"; ChatMessageBox.Text += "\n"; SendMessageBox.Clear(); } } }
private void FriendButtonRemove_Click(object sender, EventArgs e) { if (ClientLogic.Connected) { string FriendUsername = (sender as Button).Tag.ToString(); if (CreateRequests.RemoveFriend(FriendUsername)) { MessageBox.Show($"Ваш приятель {FriendUsername} був видалений."); if (FriendUsername == FriendUsernameLable.Text) { FriendUsernameLable.Text = "Ім'я вашого приятеля:"; ChatMessageBox.Clear(); ChatMessageBox.Enabled = false; SendMessageBox.Clear(); SendMessageBox.Enabled = false; SendButton.Enabled = false; StatusFriend.Visible = false; FriendUsernameLable.Visible = false; } } RefreshFriendsToList(CreateRequests.GetFriendList()); } }
private void InitializeEvents() { this.ConnectButton.Click += (object sender, EventArgs e) => { _chatClient.Connect(NameBox.Text, IpBox.Text, Convert.ToInt32(PortBox.Text)); // <---- Connecting this }; _chatClient.Connected += (endPoint) => { MessagesBox.Items.Add("Connected to " + endPoint); ConnectButton.Visible = false; DisconnectButton.Visible = true; IpBox.Enabled = false; PortBox.Enabled = false; NameBox.Enabled = false; SendMessageButton.Enabled = true; Thread receiveThread = new Thread(new ThreadStart(_chatClient.ReceiveMessage)); receiveThread.Start(); _chatClient.SendMessage("connect#" + NameBox.Text); }; _chatClient.ConnectedError += (endPoint) => { MessagesBox.Items.Add("Unsuccessful connection to " + endPoint); DisconnectButton.Visible = false; ConnectButton.Visible = true; NameBox.Enabled = true; IpBox.Enabled = true; PortBox.Enabled = true; SendMessageButton.Enabled = false; }; this.DisconnectButton.Click += (sender, e) => { _chatClient.SendMessage("disconnect#" + NameBox.Text); _chatClient.Disconnect(); // <---- Disconnecting this }; _chatClient.Disconnected += () => { MessagesBox.Items.Add("Disconnected."); DisconnectButton.Visible = false; ConnectButton.Visible = true; NameBox.Enabled = true; IpBox.Enabled = true; PortBox.Enabled = true; SendMessageButton.Enabled = false; }; this.SendMessageButton.Click += (sender, e) => { MessagesBox.Items.Add("You:" + SendMessageBox.Text); _chatClient.SendMessage("say#" + NameBox.Text + ":" + SendMessageBox.Text); // <---- Send message (1/2) }; this.SendMessageBox.KeyDown += (object sender, KeyEventArgs e) => { if (e.KeyCode == Keys.Enter) { e.SuppressKeyPress = true; MessagesBox.Items.Add("You:" + SendMessageBox.Text); _chatClient.SendMessage("say#" + NameBox.Text + "#" + SendMessageBox.Text); // <---- Send message (1/2) } }; _chatClient.MessageSended += () => { SendMessageBox.Text = ""; SendMessageBox.Select(); }; }