using System; using System.Collections.Generic; using System.Linq; using System.Text;…
- User
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes;
namespace WpfAppEindprojectOp12021 { /// /// Interaction logic for MainWindow.xaml /// public partial class MainWindow : Window { int _count = 0; bool btn1 = false; bool btn2 = false; bool btn3 = false; bool btn4 = false; public MainWindow() { InitializeComponent(); }
private void btOne_Click(object sender, RoutedEventArgs e) { btn1 = true; btOne.Background = Brushes.LightGray; btOne.Content = "Button 1 is pressed"; DoMyThing(); } private void btTwo_Click(object sender, RoutedEventArgs e) { btn2 = true; DoMyThing(); } private void btThree_Click(object sender, RoutedEventArgs e) { btn3 = true; DoMyThing(); } private void btFour_Click(object sender, RoutedEventArgs e) { btn4 = true; DoMyThing(); } private void DoMyThing() { if (!btn1 && !btn2 && !btn3 && !btn4) { gridColor.Background = Brushes.White; } else if (btn1 && !btn2 && !btn3 && !btn4) { gridColor.Background = Brushes.Red; } else if (btn1 && btn2 && btn3 && !btn4) { gridColor.Background = Brushes.Green; } else if (btn1 && btn2 && !btn3 && !btn4) { gridColor.Background = Brushes.Yellow; } else if (!btn1 && !btn2 && btn3 && btn4) { gridColor.Background = Brushes.Blue; } else if (btn1 && btn2 && btn3 && btn4) { gridColor.Background = Brushes.Black; } else { gridColor.Background = Brushes.Purple; } } private void Button_Click(object sender, RoutedEventArgs e) { _count++; tbCounter.Text = _count.ToString(); } private void Button_Click_1(object sender, RoutedEventArgs e) { double getal = Convert.ToDouble(Begin.Text); double macht = Convert.ToDouble(tbPower.Text); tbReeks.Text = ""; if (macht > 0) { for (int i = 0; i < macht; i++) { double uitkomst = Math.Pow(getal, i); tbReeks.Text += uitkomst.ToString(); if (i != macht) { tbReeks.Text += ","; } } } else { tbReeks.Text += ","; } } using System.Windows;using System.Windows.Controls;
namespace YourNamespace { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); InitializeComboBox(); }
private void InitializeComboBox() { comboBoxAnimals.Items.Add(new ComboBoxItem { Content = "Paard" }); comboBoxAnimals.Items.Add(new ComboBoxItem { Content = "Ezel" }); comboBoxAnimals.Items.Add(new ComboBoxItem { Content = "Giraf" }); comboBoxAnimals.Items.Add(new ComboBoxItem { Content = "Aap" }); comboBoxAnimals.Items.Add(new ComboBoxItem { Content = "Leeuw" }); } private void tbAnimal_TextChanged(object sender, TextChangedEventArgs e) { // Implement text changed logic if required } private void buttonCheck_Click(object sender, RoutedEventArgs e) { string animalString = tbAnimal.Text.Trim(); bool found = false; for (int i = 0; i < comboBoxAnimals.Items.Count; i++) { ComboBoxItem item = (ComboBoxItem)comboBoxAnimals.Items[i]; if (item.Content.ToString().Equals(animalString, StringComparison.OrdinalIgnoreCase)) { found = true; MessageBox.Show($"'{animalString}' is gevonden in de ComboBox op positie {i + 1}."); break; } } if (!found) { MessageBoxResult result = MessageBox.Show($"'{animalString}' is niet gevonden. Wil je het toevoegen?", "Dier Toevoegen", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { comboBoxAnimals.Items.Add(new ComboBoxItem { Content = animalString }); MessageBox.Show($"'{animalString}' is toegevoegd aan de ComboBox."); } } } } } - Assistant
- User
comboboxanimals has error, does it need defining?
- Assistant