Изменения в форме FormCar

This commit is contained in:
prodigygirl 2022-10-08 17:39:18 +04:00
parent bbd11c3210
commit b85628c4e6
2 changed files with 79 additions and 7 deletions

View File

@ -39,6 +39,8 @@ namespace ArmoredCar
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonSelectArmoredCar = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
this.statusStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCar)).BeginInit();
this.SuspendLayout();
@ -144,11 +146,35 @@ namespace ArmoredCar
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonSelectArmoredCar
//
this.buttonSelectArmoredCar.Location = new System.Drawing.Point(545, 382);
this.buttonSelectArmoredCar.Name = "buttonSelectArmoredCar";
this.buttonSelectArmoredCar.Size = new System.Drawing.Size(75, 23);
this.buttonSelectArmoredCar.TabIndex = 12;
this.buttonSelectArmoredCar.Text = "Выбрать";
this.buttonSelectArmoredCar.UseVisualStyleBackColor = true;
this.buttonSelectArmoredCar.Click += new System.EventHandler(this.buttonSelectArmoredCar_Click);
//
// buttonCreateModif
//
this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateModif.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonCreateModif.Location = new System.Drawing.Point(148, 382);
this.buttonCreateModif.Name = "buttonCreateModif";
this.buttonCreateModif.Size = new System.Drawing.Size(109, 23);
this.buttonCreateModif.TabIndex = 13;
this.buttonCreateModif.Text = "Модификация";
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.buttonCreateModif_Click);
//
// FormCar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonSelectArmoredCar);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonLeft);
@ -178,6 +204,8 @@ namespace ArmoredCar
private System.Windows.Forms.Button buttonLeft;
private System.Windows.Forms.Button buttonDown;
private System.Windows.Forms.Button buttonRight;
private System.Windows.Forms.Button buttonSelectArmoredCar;
private System.Windows.Forms.Button buttonCreateModif;
}
}

View File

@ -14,6 +14,8 @@ namespace ArmoredCar
{
private DrawningArmoredCar _car;
public DrawningArmoredCar SelectedCar { get; private set; }
public FormCar()
{
InitializeComponent();
@ -28,6 +30,16 @@ namespace ArmoredCar
_car?.DrawTransport(gr);
pictureBoxCar.Image = bmp;
}
private void SetData()
{
Random rnd = new();
_car.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_car.ArmoredCar.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_car.ArmoredCar.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_car.ArmoredCar.BodyColor.Name}";
}
/// <summary>
/// Обработка нажатия кнопки "Создать"
/// </summary>
@ -36,13 +48,14 @@ namespace ArmoredCar
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
_car = new DrawningArmoredCar(rnd.Next(100, 300), rnd.Next(1000, 2000),
Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
_car.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height);
toolStripStatusLabelSpeed.Text = $"Скорость: {_car.ArmoredCar.Speed}";
toolStripStatusLabelWeight.Text = $"Вес: {_car.ArmoredCar.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: { _car.ArmoredCar.BodyColor.Name}";
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
_car = new DrawningArmoredCar(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
/// <summary>
@ -81,5 +94,36 @@ namespace ArmoredCar
_car?.ChangeBorders(pictureBoxCar.Width, pictureBoxCar.Height);
Draw();
}
private void buttonSelectArmoredCar_Click(object sender, EventArgs e)
{
SelectedCar = _car;
DialogResult = DialogResult.OK;
}
private void buttonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
ColorDialog dialogDop = new();
if (dialogDop.ShowDialog() == DialogResult.OK)
{
dopColor = dialogDop.Color;
}
_car = new DrawningTank(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
}
}