0
I’m having doubts about how to add a line of 4 colors, line by line:
As shown:
At each push of a button.
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 mastercode_v1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
//color para os quadrados e para os botões
private Brush[] colorsGeneral = { Brushes.Blue, Brushes.Red, Brushes.Yellow,Brushes.Green,Brushes.Black };
// so é utilizado para os pins de marcação para o codemaster para indicar em quantas marcou (branco acertou na cor mas não no sitio , red no sitio e a cor , preto nem na cor nem no sitio)
private Brush[] colorsPins = { Brushes.White, Brushes.Red, Brushes.Black };
private int index = 0;
//var to load the color brush for 1º square
private Brush P1 { get; set; }
private Brush P2 { get; set; }
private Brush P3 { get; set; }
private Brush P4 { get; set; }
private void buttonC1_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
index++;
index %= colorsGeneral.Length;
button.Background = colorsGeneral[index];
P1= colorsGeneral[index];
}
private void buttonC2_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
index++;
index %= colorsGeneral.Length;
button.Background = colorsGeneral[index];
P2= colorsGeneral[index];
}
private void buttonC3_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
index++;
index %= colorsGeneral.Length;
button.Background = colorsGeneral[index];
P3= colorsGeneral[index];
}
private void buttonC4_Click(object sender, RoutedEventArgs e)
{
Button button = (Button)sender;
index++;
index %= colorsGeneral.Length;
button.Background = colorsGeneral[index];
P4= colorsGeneral[index];
}
private void buttonUse_Click(object sender, RoutedEventArgs e)
{
//r1 is square 1 , r2 square 2
r1.Fill = P1;
r2.Fill = P2;
r3.Fill = P3;
r4.Fill = P4;
}
}
}
<Window x:Class="mastercode_v1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:mastercode_v1"
mc:Ignorable="d"
Title="MainWindow" Height="422" Width="464">
<Grid Margin="0,0,-19,-16">
<Rectangle Name="r1" HorizontalAlignment="Left" Height="28" Margin="48,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle Name="r2" HorizontalAlignment="Left" Height="28" Margin="81,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle Name="r3" HorizontalAlignment="Left" Height="28" Margin="114,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle Name="r4" HorizontalAlignment="Left" Height="28" Margin="147,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,161,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,161,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,161,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,161,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,194,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,194,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,194,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,194,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,23,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,37,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,37,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,56,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,70,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,70,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,91,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,105,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,105,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,124,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,138,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,138,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="48,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="81,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="114,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="28"/>
<Rectangle HorizontalAlignment="Left" Height="28" Margin="147,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="28" RenderTransformOrigin="1.321,0.716"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,159,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,159,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,173,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,173,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,192,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,206,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,206,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,227,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,241,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,241,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,260,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Rectangle HorizontalAlignment="Left" Height="14" Margin="192,274,0,0" Stroke="Black" VerticalAlignment="Top" Width="16"/>
<Rectangle HorizontalAlignment="Center" Height="14" Margin="0,274,0,0" Stroke="Black" VerticalAlignment="Top" Width="16" RenderTransformOrigin="2.125,1.074"/>
<Button Name="buttonC1" Content="Color" HorizontalAlignment="Left" Margin="10,318,0,0" VerticalAlignment="Top" Click="buttonC1_Click"/>
<Button Name="buttonUse" Content="Use" HorizontalAlignment="Center" Margin="0,323,0,0" VerticalAlignment="Top" Click="buttonUse_Click"/>
<Button Name="buttonC2" Content="Color" HorizontalAlignment="Left" Margin="55,318,0,0" VerticalAlignment="Top" Click="buttonC2_Click"/>
<Button Name="buttonC3" Content="Color" HorizontalAlignment="Left" Margin="102,318,0,0" VerticalAlignment="Top" Click="buttonC3_Click"/>
<Button Name="buttonC4" Content="Color" HorizontalAlignment="Left" Margin="147,318,0,0" VerticalAlignment="Top" Click="buttonC4_Click"/>
</Grid>
</Window>```