Проктирование формы

This commit is contained in:
Максим Егоров 2024-01-15 23:05:56 +03:00
parent 375e66b131
commit 0f2fc1be54
5 changed files with 231 additions and 167 deletions

View File

@ -23,7 +23,6 @@ namespace Sailboat.DrawingObjects
public int GetWidth => _boatWidth;
public int GetHeight => _boatHeight;
public IMoveableObject GetMoveableObject => new DrawingObjectBoat(this);
public DrawingBoat(int speed, double weight, Color bodyColor, int width, int height)
{
if (width < _boatWidth || height < _boatHeight)
@ -76,11 +75,12 @@ namespace Sailboat.DrawingObjects
DirectionType.Right => _startPosX + EntityBoat.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + EntityBoat.Step < _pictureHeight,
_ => false
};
}
public void MoveTransport(DirectionType direction)
{
if (EntityBoat == null)
if (!CanMove(direction) || EntityBoat == null)
{
return;
}
@ -93,7 +93,7 @@ namespace Sailboat.DrawingObjects
}
break;
case DirectionType.Up:
if ((_startPosY - 15) - EntityBoat.Step > 0)
if (_startPosY - EntityBoat.Step > 0)
{
_startPosY -= (int)EntityBoat.Step;
}
@ -122,7 +122,7 @@ namespace Sailboat.DrawingObjects
Brush additionalBrush = new
SolidBrush(EntityBoat.BodyColor);
//Основной корпус лодки
//основной корпус парусника
Brush Brush = new
SolidBrush(EntityBoat.BodyColor);
@ -138,14 +138,12 @@ namespace Sailboat.DrawingObjects
g.DrawPolygon(pen, hull);
Brush addBrush = new
SolidBrush(Color.Aqua);
SolidBrush(Color.Green);
//Каюта лодки
g.FillEllipse(addBrush, _startPosX + 20, _startPosY + 100, 90, 40);
g.DrawEllipse(pen, _startPosX + 20, _startPosY + 100, 90, 40);
}
}
}
}

View File

@ -30,7 +30,7 @@ namespace Sailboat.DrawingObjects
Brush additionalBrush = new
SolidBrush(sailboat.AdditionalColor);
//усиленный корпус парусной лодки
//усиленный корпус парусника
if (sailboat.Hull)
{
Point[] hullCooler = new Point[]
@ -43,10 +43,11 @@ namespace Sailboat.DrawingObjects
};
g.FillPolygon(additionalBrush, hullCooler);
g.DrawPolygon(pen, hullCooler);
}
base.DrawTransport(g);
//Парус с флагом
}
base.DrawTransport(g);
//парус
if (sailboat.Sail)
{
Brush sailBrush = new
@ -60,21 +61,7 @@ namespace Sailboat.DrawingObjects
};
g.FillPolygon(sailBrush, sail);
g.DrawPolygon(pen, sail);
//Флаг
Brush addBrush = new
SolidBrush(Color.Aqua);
Brush flagBrush = new
SolidBrush(sailboat.AdditionalColor);
Point[] flag = new Point[]
{
new Point(_startPosX + 65, _startPosY - 15),
new Point(_startPosX + 65, _startPosY + 10),
new Point(_startPosX + 20, _startPosY + 10),
new Point(_startPosX + 20, _startPosY - 15),
};
g.FillPolygon(addBrush, flag);
g.DrawPolygon(pen, flag);
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 130), new Point(_startPosX + 65, _startPosY - 15));
g.DrawLine(pen, new Point(_startPosX + 65, _startPosY + 120), new Point(_startPosX + 65, _startPosY));
}
}
}

View File

@ -28,96 +28,147 @@
/// </summary>
private void InitializeComponent()
{
pictureBoxCollection = new PictureBox();
panelTools = new Panel();
maskedTextBoxNumber = new MaskedTextBox();
buttonRefreshCollection = new Button();
buttonRemoveBoat = new Button();
buttonAddBoat = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
panelTools.SuspendLayout();
SuspendLayout();
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
this.panelTools = new System.Windows.Forms.Panel();
this.panelCollection = new System.Windows.Forms.Panel();
this.buttonDelObject = new System.Windows.Forms.Button();
this.listBoxStorages = new System.Windows.Forms.ListBox();
this.buttonAddObject = new System.Windows.Forms.Button();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.buttonRefreshCollection = new System.Windows.Forms.Button();
this.buttonRemoveBoat = new System.Windows.Forms.Button();
this.buttonAddBoat = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
this.panelTools.SuspendLayout();
this.panelCollection.SuspendLayout();
this.SuspendLayout();
//
// pictureBoxCollection
//
pictureBoxCollection.Location = new Point(0, 0);
pictureBoxCollection.Margin = new Padding(3, 2, 3, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(750, 450);
pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxCollection.TabIndex = 0;
pictureBoxCollection.TabStop = false;
pictureBoxCollection.Click += pictureBoxCollection_Click;
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
this.pictureBoxCollection.Name = "pictureBoxCollection";
this.pictureBoxCollection.Size = new System.Drawing.Size(750, 600);
this.pictureBoxCollection.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxCollection.TabIndex = 0;
this.pictureBoxCollection.TabStop = false;
//
// panelTools
//
panelTools.BackColor = SystemColors.ScrollBar;
panelTools.Controls.Add(maskedTextBoxNumber);
panelTools.Controls.Add(buttonRefreshCollection);
panelTools.Controls.Add(buttonRemoveBoat);
panelTools.Controls.Add(buttonAddBoat);
panelTools.Location = new Point(662, 9);
panelTools.Margin = new Padding(3, 2, 3, 2);
panelTools.Name = "panelTools";
panelTools.Size = new Size(183, 320);
panelTools.TabIndex = 1;
this.panelTools.BackColor = System.Drawing.SystemColors.ScrollBar;
this.panelTools.Controls.Add(this.panelCollection);
this.panelTools.Controls.Add(this.maskedTextBoxNumber);
this.panelTools.Controls.Add(this.buttonRefreshCollection);
this.panelTools.Controls.Add(this.buttonRemoveBoat);
this.panelTools.Controls.Add(this.buttonAddBoat);
this.panelTools.Location = new System.Drawing.Point(756, 12);
this.panelTools.Name = "panelTools";
this.panelTools.Size = new System.Drawing.Size(209, 588);
this.panelTools.TabIndex = 1;
//
// panelCollection
//
this.panelCollection.BackColor = System.Drawing.SystemColors.AppWorkspace;
this.panelCollection.Controls.Add(this.buttonDelObject);
this.panelCollection.Controls.Add(this.listBoxStorages);
this.panelCollection.Controls.Add(this.buttonAddObject);
this.panelCollection.Controls.Add(this.textBoxStorageName);
this.panelCollection.Location = new System.Drawing.Point(16, 15);
this.panelCollection.Name = "panelCollection";
this.panelCollection.Size = new System.Drawing.Size(181, 287);
this.panelCollection.TabIndex = 4;
//
// buttonDelObject
//
this.buttonDelObject.Location = new System.Drawing.Point(12, 230);
this.buttonDelObject.Name = "buttonDelObject";
this.buttonDelObject.Size = new System.Drawing.Size(154, 34);
this.buttonDelObject.TabIndex = 5;
this.buttonDelObject.Text = "Удалить набор";
this.buttonDelObject.UseVisualStyleBackColor = true;
this.buttonDelObject.Click += new System.EventHandler(this.buttonDelObject_Click);
//
// listBoxStorages
//
this.listBoxStorages.FormattingEnabled = true;
this.listBoxStorages.ItemHeight = 20;
this.listBoxStorages.Location = new System.Drawing.Point(12, 102);
this.listBoxStorages.Name = "listBoxStorages";
this.listBoxStorages.Size = new System.Drawing.Size(154, 104);
this.listBoxStorages.TabIndex = 6;
this.listBoxStorages.SelectedIndexChanged += new System.EventHandler(this.ListBoxObjects_SelectedIndexChanged);
//
// buttonAddObject
//
this.buttonAddObject.Location = new System.Drawing.Point(12, 62);
this.buttonAddObject.Name = "buttonAddObject";
this.buttonAddObject.Size = new System.Drawing.Size(154, 34);
this.buttonAddObject.TabIndex = 5;
this.buttonAddObject.Text = "Добавить набор";
this.buttonAddObject.UseVisualStyleBackColor = true;
this.buttonAddObject.Click += new System.EventHandler(this.buttonAddObject_Click);
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(29, 29);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(125, 27);
this.textBoxStorageName.TabIndex = 0;
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(35, 65);
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(110, 23);
maskedTextBoxNumber.TabIndex = 3;
this.maskedTextBoxNumber.Location = new System.Drawing.Point(45, 416);
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.TabIndex = 3;
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(14, 158);
buttonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(158, 26);
buttonRefreshCollection.TabIndex = 2;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
buttonRefreshCollection.Click += buttonRefreshCollection_Click;
this.buttonRefreshCollection.Location = new System.Drawing.Point(16, 531);
this.buttonRefreshCollection.Name = "buttonRefreshCollection";
this.buttonRefreshCollection.Size = new System.Drawing.Size(180, 34);
this.buttonRefreshCollection.TabIndex = 2;
this.buttonRefreshCollection.Text = "Обновить коллекцию";
this.buttonRefreshCollection.UseVisualStyleBackColor = true;
this.buttonRefreshCollection.Click += new System.EventHandler(this.buttonRefreshCollection_Click);
//
// buttonRemoveBoat
//
buttonRemoveBoat.Location = new Point(14, 119);
buttonRemoveBoat.Margin = new Padding(3, 2, 3, 2);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(158, 26);
buttonRemoveBoat.TabIndex = 1;
buttonRemoveBoat.Text = "Удалить лодку";
buttonRemoveBoat.UseVisualStyleBackColor = true;
buttonRemoveBoat.Click += buttonRemoveBoat_Click;
this.buttonRemoveBoat.Location = new System.Drawing.Point(17, 469);
this.buttonRemoveBoat.Name = "buttonRemoveBoat";
this.buttonRemoveBoat.Size = new System.Drawing.Size(180, 34);
this.buttonRemoveBoat.TabIndex = 1;
this.buttonRemoveBoat.Text = "Удалить лодку";
this.buttonRemoveBoat.UseVisualStyleBackColor = true;
this.buttonRemoveBoat.Click += new System.EventHandler(this.buttonRemoveBoat_Click);
//
// buttonAddBoat
//
buttonAddBoat.Location = new Point(14, 10);
buttonAddBoat.Margin = new Padding(3, 2, 3, 2);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(158, 26);
buttonAddBoat.TabIndex = 0;
buttonAddBoat.Text = "Добавить лодку";
buttonAddBoat.UseVisualStyleBackColor = true;
buttonAddBoat.Click += buttonAddBoat_Click;
this.buttonAddBoat.Location = new System.Drawing.Point(16, 339);
this.buttonAddBoat.Name = "buttonAddBoat";
this.buttonAddBoat.Size = new System.Drawing.Size(180, 34);
this.buttonAddBoat.TabIndex = 0;
this.buttonAddBoat.Text = "Добавить лодку";
this.buttonAddBoat.UseVisualStyleBackColor = true;
this.buttonAddBoat.Click += new System.EventHandler(this.buttonAddBoat_Click);
//
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(848, 338);
Controls.Add(pictureBoxCollection);
Controls.Add(panelTools);
Margin = new Padding(3, 2, 3, 2);
Name = "FormBoatCollection";
Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
panelTools.ResumeLayout(false);
panelTools.PerformLayout();
ResumeLayout(false);
PerformLayout();
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(969, 604);
this.Controls.Add(this.panelTools);
this.Controls.Add(this.pictureBoxCollection);
this.Name = "FormBoatCollection";
this.Text = "FormBoatCollection";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
this.panelTools.ResumeLayout(false);
this.panelTools.PerformLayout();
this.panelCollection.ResumeLayout(false);
this.panelCollection.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
@ -128,5 +179,10 @@
private Button buttonRemoveBoat;
private Button buttonAddBoat;
private MaskedTextBox maskedTextBoxNumber;
private Panel panelCollection;
private Button buttonDelObject;
private ListBox listBoxStorages;
private Button buttonAddObject;
private TextBox textBoxStorageName;
}
}

View File

@ -17,22 +17,55 @@ namespace Sailboat
{
public partial class FormBoatCollection : Form
{
private readonly BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> _boats;
private readonly BoatsGenericStorage _storage;
public FormBoatCollection()
{
InitializeComponent();
_boats = new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(pictureBoxCollection.Width, pictureBoxCollection.Height);
_storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
}
private void ReloadObjects()
{
int index = listBoxStorages.SelectedIndex;
listBoxStorages.Items.Clear();
for (int i = 0; i < _storage.Keys.Count; i++)
{
listBoxStorages.Items.Add(_storage.Keys[i]);
}
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
>= listBoxStorages.Items.Count))
{
listBoxStorages.SelectedIndex = 0;
}
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
index < listBoxStorages.Items.Count)
{
listBoxStorages.SelectedIndex = index;
}
}
private void buttonAddBoat_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
FormSailboat form = new();
if (form.ShowDialog() == DialogResult.OK)
{
if (_boats + form.SelectedBoat != -1)
if (obj + form.SelectedBoat)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _boats.ShowBoats();
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
@ -43,30 +76,80 @@ namespace Sailboat
private void buttonRemoveBoat_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_boats - pos != null)
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = obj.ShowBoats();
}
else
{
MessageBox.Show("Не удалось удалить объект");
pictureBoxCollection.Image = _boats.ShowBoats();
}
}
private void buttonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollection.Image = _boats.ShowBoats();
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollection.Image = obj.ShowBoats();
}
private void pictureBoxCollection_Click(object sender, EventArgs e)
private void buttonAddObject_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBoxStorageName.Text))
{
MessageBox.Show("Не все данные заполнены", "Ошибка",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_storage.AddSet(textBoxStorageName.Text);
ReloadObjects();
}
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBoxCollection.Image =
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats();
}
private void buttonDelObject_Click(object sender, EventArgs e)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
if (MessageBox.Show($"Удалить объект { listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
?? string.Empty);
ReloadObjects();
}
}
}
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">