PHP код:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ColorChanger
{
public partial class Form1 : Form
{
Panel[] ColorView;
int OldSteps = 0;
static void HexToRGB(Color HEX_COLOR, ref int R, ref int G, ref int B)
{
R = HEX_COLOR.R;
G = HEX_COLOR.G;
B = HEX_COLOR.B;
}
public Form1()
{
InitializeComponent();
}
private void ChangeColor(object sender, EventArgs e)
{
MaskedTextBox A = (sender as MaskedTextBox);
if (A.Text.Length > 0)
{
int R = 0, G = 0, B = 0;
object ChangePanel = panel1;
try
{
HexToRGB(ColorTranslator.FromHtml('#' + A.Text), ref R, ref G, ref B);
if (sender == maskedTextBox2) ChangePanel = panel2;
(ChangePanel as Panel).BackColor = Color.FromArgb(255, R, G, B);
}
catch
{
A.Text = A.Text.Substring(0, A.Text.Length - 1);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
textBox1.Clear();
if (maskedTextBox1.Text.Length > 0 && maskedTextBox2.Text.Length > 0 && maskedTextBox3.Text.Length > 0)
{
int Steps = Convert.ToInt32(maskedTextBox3.Text);
if (Steps >= 1 && Steps <= 100)
{
if (OldSteps > 0)
{
for (int i = 0; i != OldSteps; i++) ColorView[i].Dispose();
}
ColorView = new Panel[Steps];
int R = 0, G = 0, B = 0, R1 = 0, G1 = 0, B1 = 0;
HexToRGB(ColorTranslator.FromHtml('#' + maskedTextBox1.Text), ref R, ref G, ref B);
HexToRGB(ColorTranslator.FromHtml('#' + maskedTextBox2.Text), ref R1, ref G1, ref B1);
int Rs = 0, Gs = 0, Bs = 0;
Rs = (R1 - R) / Steps;
Gs = (G1 - G) / Steps;
Bs = (B1 - B) / Steps;
int SizeBlock = 336 / Steps;
OldSteps = Steps;
int Difference = Steps - (336 - SizeBlock * Steps);
for (int i = 0, ColorIndex = 43; i != Steps; i++, ColorIndex += SizeBlock)
{
if (i == Difference) SizeBlock++;
R += Rs;
G += Gs;
B += Bs;
String S = ColorTranslator.ToHtml(Color.FromArgb(255, R, G, B));
textBox1.Text += (S.Substring(1, S.Length - 1) + Environment.NewLine);
ColorView[i] = new Panel();
ColorView[i].Location = new Point(ColorIndex, 12);
ColorView[i].Size = new Size(SizeBlock, 80);
ColorView[i].BackColor = Color.FromArgb(255, R, G, B);
ColorView[i].Visible = true;
this.Controls.Add(ColorView[i]);
}
}
else textBox1.Text = "Число шагов от 1 до 100.";
}
}
private void button2_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(textBox1.Text, true);
}
}
}