From a3a48959b5484e5ba36e743f0ddbba98cd292704 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Peyronnet?= Date: Wed, 15 Sep 2021 15:23:02 +0200 Subject: [PATCH] Added a button to generate a random color (#53) --- ColorPicker/Pages/PalettePage.xaml | 13 ++++++++++++- ColorPicker/Pages/PalettePage.xaml.cs | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ColorPicker/Pages/PalettePage.xaml b/ColorPicker/Pages/PalettePage.xaml index 71c72ab..d209817 100644 --- a/ColorPicker/Pages/PalettePage.xaml +++ b/ColorPicker/Pages/PalettePage.xaml @@ -19,7 +19,18 @@ - + + + + + + + + diff --git a/ColorPicker/Pages/PalettePage.xaml.cs b/ColorPicker/Pages/PalettePage.xaml.cs index e7a3b58..b25f543 100644 --- a/ColorPicker/Pages/PalettePage.xaml.cs +++ b/ColorPicker/Pages/PalettePage.xaml.cs @@ -120,5 +120,18 @@ private void RGBTxt_TextChanged(object sender, TextChangedEventArgs e) } } + + private void RandomColorBtn_Click(object sender, RoutedEventArgs e) + { + // Generate random color + int r, g, b; + Random random = new(); + + r = random.Next(0, 255); // Generate random number between 0 and 255 + g = random.Next(0, 255); // Generate random number between 0 and 255 + b = random.Next(0, 255); // Generate random number between 0 and 255 + + RGBTxt.Text = $"{r}{Global.Settings.RGBSeparator}{g}{Global.Settings.RGBSeparator}{b}"; // Set text + } } }