public void addReceiverAccount(string name, IPEndPoint epClient) { //adding active account int accountDataIndex = addActiveAccount(name, "new account"); //make new userAccount userAccountCustom newCustom = new userAccountCustom(name, "new account"); newCustom.Width = 290; newCustom.accountSock = "receiver"; //onclick event of this control //set focused buttonFocused = name; //event newCustom.MouseDown += (sender, EventArgs) => { //retract messageComposer.show(); messageComposer.clientSocks = "receiver"; //add endpoint messageComposer.clientsEP = epClient; //adding all messages messageBox.Children.Clear(); for (int b = 0; b != activeAccounts[accountDataIndex].messages.Length; b++) { if (activeAccounts[accountDataIndex].messageCount + 1 == b) { break; } else { messageDialougeCustom newDialouge = new messageDialougeCustom(activeAccounts[accountDataIndex].messages[b].message, new Thickness(0, 20, 100, 0)); newDialouge.HorizontalAlignment = HorizontalAlignment.Left; if (activeAccounts[accountDataIndex].messages[b].from == "client") { newDialouge.HorizontalAlignment = HorizontalAlignment.Right; } SolidColorBrush messagecolor = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF321779")); newDialouge.messageColor.Background = messagecolor; messageBox.Children.Add(newDialouge); } } }; //add item AccountStack.Children.Add(newCustom); }
public void messageReceived(string account, string message, IPEndPoint remoteServer) { Boolean accountExists = false; int accountDataIndex = 0; //check if the account exists for (int i = 0; i != activeAccounts.Length; i++) { //check if it is blank (because if blank nothing else is infront) if (activeAccounts[i] == null) { break; } else { if (activeAccounts[i].username == account) { accountExists = true; accountDataIndex = i; break; } } } //if account doent exist if (accountExists == false) { //add to account stack for (int i = 0; i != activeAccounts.Length; i++) { if (activeAccounts[i] == null) { //make new active account activeAccounts[i] = new accountData(account, message); //set data pointer accountDataIndex = i; //make new userAccount userAccountCustom newCustom = new userAccountCustom(account, message); newCustom.Width = 290; //onclick event of this control //set focused buttonFocused = account; //event newCustom.MouseDown += (sender, EventArgs) => { //set index for composer messageComposer.activeAccountIndex = i; //retract messageComposer.show(); //add endpoint messageComposer.clientsEP = remoteServer; messageComposer.clientSocks = "sender"; //adding all messages messageBox.Children.Clear(); for (int b = 0; b != activeAccounts[accountDataIndex].messages.Length; b++) { if (activeAccounts[accountDataIndex].messageCount + 1 == b) { break; } else { messageDialougeCustom newDialouge = new messageDialougeCustom(activeAccounts[accountDataIndex].messages[b].message, new Thickness(0, 20, 100, 0)); newDialouge.HorizontalAlignment = HorizontalAlignment.Left; if (activeAccounts[accountDataIndex].messages[b].from == "client") { newDialouge.HorizontalAlignment = HorizontalAlignment.Right; } SolidColorBrush messagecolor = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF321779")); newDialouge.messageColor.Background = messagecolor; messageBox.Children.Add(newDialouge); } } }; //set account socks newCustom.accountSock = "sender"; //adding to stack AccountStack.Children.Add(newCustom); //break break; } } } //if account exists if (accountExists == true) { //adding message to accountData activeAccounts[accountDataIndex].addMessage(message, "client"); //check if focused if (buttonFocused == activeAccounts[accountDataIndex].username) { //adding message messageDialougeCustom newDialouge = new messageDialougeCustom(message, new Thickness(0, 20, 100, 0)); newDialouge.HorizontalAlignment = HorizontalAlignment.Left; if (activeAccounts[accountDataIndex].messages[accountDataIndex].from == "client") { newDialouge.HorizontalAlignment = HorizontalAlignment.Right; } SolidColorBrush messagecolor = (SolidColorBrush)(new BrushConverter().ConvertFrom("#FF321779")); newDialouge.messageColor.Background = messagecolor; messageBox.Children.Add(newDialouge); } } }