private void AddAccountItem(Account account) { // Create an account item based on the specified account AccountItem item = new AccountItem(account); // Register the custom click event to handle selection item.ItemClicked += (sender, e) => { // Either unselect the item if its already selected or select it if (m_selected == sender) { // Unselect the item m_selected.Unselect(); // set the selected item to null m_selected = null; } else { // Unselect the currently selected item if not null m_selected?.Unselect(); // Change the selected item and select it m_selected = sender as AccountItem; m_selected.Select(); } // Update the UI to apply selection change btnRemoveAccount.Enabled = m_selected != null; }; // Add the item control to the flow layout panel flwpnlAccounts.Controls.Add(item); }