示例#1
0
        public static int ordenarColor(PaletaColeccion pal1, PaletaColeccion pal2)
        {
            int retorno = 0;

            if (pal1._colores == pal2._colores)
            {
                retorno = 0;
            }
            return(retorno);
        }
        private void btnMas_Click(object sender, EventArgs e)
        {
            FrmTempera colores = new FrmTempera();

            if (colores.ShowDialog() == DialogResult.OK)
            {
                this.txtColores.Clear();
                this._paleta    += colores.Tempera;
                txtColores.Text += (string)this._paleta;
            }
        }
 public FrmPaleta()
 {
     InitializeComponent();
     this._paleta                 = 5;
     this.grpColores.Text         = "Paleta de colores";
     this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
     this.comboBox1.Items.Add("Por color (A-Z)");
     this.comboBox1.Items.Add("Por marca (A-Z)");
     this.comboBox1.Items.Add("Por cantidad (Ascendente)");
     this.comboBox1.Items.Add("Por cantidad (Descendente)");
     this.comboBox1.SelectedItem = "Por marca (A-Z)";
     this.txtColores.Multiline   = true;
     this.grpColores.Visible     = false;
     this.txtColores.Visible     = false;
     this.btnMas.Text            = "+";
     this.btnMenos.Text          = "-";
 }
        public static PaletaColeccion operator +(PaletaColeccion PaletaColeccion, Tempera tempera)
        {
            int index;

            if (PaletaColeccion._colores.Count < PaletaColeccion._cantMaximaElementos)
            {
                if (PaletaColeccion == tempera)
                {
                    index = PaletaColeccion.ObtenerIndice(tempera);
                    PaletaColeccion._colores[index] += tempera;
                }
                else
                {
                    PaletaColeccion._colores.Add(tempera);
                }
            }
            return(PaletaColeccion);
        }
        public static PaletaColeccion operator -(PaletaColeccion PaletaColeccion, Tempera tempera)
        {
            int   index = PaletaColeccion.ObtenerIndice(tempera);
            sbyte resta;

            if (index > -1)
            {
                resta = (sbyte)((sbyte)(tempera) * (sbyte)-1);
                if ((sbyte)(PaletaColeccion._colores[index] + resta) >= 0)
                {
                    PaletaColeccion._colores[index] += resta;
                }
                else
                {
                    PaletaColeccion._colores.RemoveAt(index);
                }
            }
            return(PaletaColeccion);
        }
        private void btnMenos_Click(object sender, EventArgs e)
        {
            string     seleccionado = this.txtColores.SelectedText;
            int        indice       = -1;
            FrmTempera frmTempera   = new FrmTempera();

            foreach (string tempera in this.txtColores.Lines)
            {
                if (seleccionado != string.Empty && seleccionado == tempera && indice > -1)
                {
                    if (frmTempera.ShowDialog() == DialogResult.OK)
                    {
                        this._paleta        -= frmTempera.Tempera;
                        this.txtColores.Text = (string)this._paleta;
                        break;
                    }
                }
                indice++;
            }
        }