Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Lab3.docx
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
3.22 Mб
Скачать

Создание класса для хранения внутреннего представления точек

Для удобства хранения данных о точках создадим простенький класс. Добавьте файл ZigzagPoint.cs в проект плагина. Вот его текст, думаю тут всё будет понятно:

/// <summary>

/// Точка ломаной. Внутреплагинное представление данных о точке ломаной на сервере.

/// </summary>

public class ZigzagPoint

{

/// <summary>

/// Конструктор точки.

/// </summary>

/// <param name="time">Время создания точки, заданное через количество прошедших мс со времени запуска сервера.</param>

/// <param name="x">Координата точки по оси X.</param>

/// <param name="y">Координата точки по оси Y.</param>

public ZigzagPoint(long time, int x, int y)

{

this.Time = time;

this.X = x;

this.Y = y;

}

/// <summary> Получает или задаёт координату точки по оси X. </summary>

public int X { get; set; }

/// <summary> Получает или задаёт координату точки по оси Y. </summary>

public int Y { get; set; }

/// <summary> Получает или задаёт время создания точки. </summary>

public long Time { get; set; }

}

Отличие его от только что реализованного нами Point в том, что тут будет запоминаться ещё и время создания. Предыдущий же класс мы используем только для взаимодействия с сервером.

Создание форм редактирования данных о точках

Здесь мне потребовалось создать две формы – одну для редактирования данных одной единственной точки, вторую – для добавления и удаления новых точек. Выглядят у меня они вот так:

Я уже многократно говорил, что не собираюсь устраивать урок по пользованию визуальным редактором. Либо делайте похожие сами, либо я вам дам код, сгенерированный дизайнером, вы его скопипастите куда надо и получите идентичные формы.

Добавляем две новых формы к проекту - ZigzagEditorForm.cs и EditPointDataForm.cs.

Разворачиваем узел дерева формы EditPointDataForm.

Открываем её файл Designer.cs и заменяем её код на следующий.

namespace Plugin1

{

partial class EditPointDataForm

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.label1 = new System.Windows.Forms.Label();

this.time_textBox = new System.Windows.Forms.TextBox();

this.label2 = new System.Windows.Forms.Label();

this.x_textBox = new System.Windows.Forms.TextBox();

this.y_textBox = new System.Windows.Forms.TextBox();

this.label3 = new System.Windows.Forms.Label();

this.ok_button = new System.Windows.Forms.Button();

this.cancel_button = new System.Windows.Forms.Button();

this.SuspendLayout();

//

// label1

//

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(12, 9);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(114, 13);

this.label1.TabIndex = 0;

this.label1.Text = "Время создания, мс:";

//

// time_textBox

//

this.time_textBox.Location = new System.Drawing.Point(132, 6);

this.time_textBox.Name = "time_textBox";

this.time_textBox.Size = new System.Drawing.Size(192, 20);

this.time_textBox.TabIndex = 1;

this.time_textBox.Click += new System.EventHandler(this.time_textBox_Click);

this.time_textBox.Leave += new System.EventHandler(this.time_textBox_Leave);

//

// label2

//

this.label2.AutoSize = true;

this.label2.Location = new System.Drawing.Point(46, 35);

this.label2.Name = "label2";

this.label2.Size = new System.Drawing.Size(80, 13);

this.label2.TabIndex = 2;

this.label2.Text = "Координата X:";

//

// x_textBox

//

this.x_textBox.Location = new System.Drawing.Point(132, 32);

this.x_textBox.Name = "x_textBox";

this.x_textBox.Size = new System.Drawing.Size(192, 20);

this.x_textBox.TabIndex = 3;

this.x_textBox.Click += new System.EventHandler(this.x_textBox_Click);

this.x_textBox.Leave += new System.EventHandler(this.x_textBox_Leave);

//

// y_textBox

//

this.y_textBox.Location = new System.Drawing.Point(132, 58);

this.y_textBox.Name = "y_textBox";

this.y_textBox.Size = new System.Drawing.Size(192, 20);

this.y_textBox.TabIndex = 5;

this.y_textBox.Click += new System.EventHandler(this.y_textBox_Click);

this.y_textBox.Leave += new System.EventHandler(this.y_textBox_Leave);

//

// label3

//

this.label3.AutoSize = true;

this.label3.Location = new System.Drawing.Point(46, 61);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(80, 13);

this.label3.TabIndex = 4;

this.label3.Text = "Координата Y:";

//

// ok_button

//

this.ok_button.Location = new System.Drawing.Point(90, 91);

this.ok_button.Name = "ok_button";

this.ok_button.Size = new System.Drawing.Size(75, 23);

this.ok_button.TabIndex = 6;

this.ok_button.Text = "OK";

this.ok_button.UseVisualStyleBackColor = true;

this.ok_button.Click += new System.EventHandler(this.ok_button_Click);

//

// cancel_button

//

this.cancel_button.Location = new System.Drawing.Point(171, 91);

this.cancel_button.Name = "cancel_button";

this.cancel_button.Size = new System.Drawing.Size(75, 23);

this.cancel_button.TabIndex = 7;

this.cancel_button.Text = "Отмена";

this.cancel_button.UseVisualStyleBackColor = true;

this.cancel_button.Click += new System.EventHandler(this.cancel_button_Click);

//

// EditPointDataForm

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(331, 126);

this.Controls.Add(this.cancel_button);

this.Controls.Add(this.ok_button);

this.Controls.Add(this.y_textBox);

this.Controls.Add(this.label3);

this.Controls.Add(this.x_textBox);

this.Controls.Add(this.label2);

this.Controls.Add(this.time_textBox);

this.Controls.Add(this.label1);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;

this.MaximizeBox = false;

this.Name = "EditPointDataForm";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Редактор данных точки";

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;

private System.Windows.Forms.TextBox time_textBox;

private System.Windows.Forms.Label label2;

private System.Windows.Forms.TextBox x_textBox;

private System.Windows.Forms.TextBox y_textBox;

private System.Windows.Forms.Label label3;

private System.Windows.Forms.Button ok_button;

private System.Windows.Forms.Button cancel_button;

}

}

Теперь, если вы дважды щёлкните по корневому элементу формы и студия покажет вам визуальный редактор форы, вы увидете, что наша с вами формы идентичны, разве что пока не объявлены обработчики событий на ней. Тот же фокус повторим с формой ZigzagEditorForm.cs. Вот код для её класса Designer.cs:

namespace Plugin1

{

partial class ZigzagEditorForm

{

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// Clean up any resources being used.

/// </summary>

/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

/// </summary>

private void InitializeComponent()

{

this.points_dataGridView = new System.Windows.Forms.DataGridView();

this.TimePassedColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();

this.xColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();

this.yColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();

this.add_button = new System.Windows.Forms.Button();

this.edit_button = new System.Windows.Forms.Button();

this.delete_button = new System.Windows.Forms.Button();

this.points_groupBox = new System.Windows.Forms.GroupBox();

this.refreshData_button = new System.Windows.Forms.Button();

this.pushToServer_button = new System.Windows.Forms.Button();

((System.ComponentModel.ISupportInitialize)(this.points_dataGridView)).BeginInit();

this.points_groupBox.SuspendLayout();

this.SuspendLayout();

//

// points_dataGridView

//

this.points_dataGridView.AllowUserToAddRows = false;

this.points_dataGridView.AllowUserToDeleteRows = false;

this.points_dataGridView.AllowUserToResizeColumns = false;

this.points_dataGridView.AllowUserToResizeRows = false;

this.points_dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;

this.points_dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {

this.TimePassedColumn,

this.xColumn,

this.yColumn});

this.points_dataGridView.Location = new System.Drawing.Point(6, 19);

this.points_dataGridView.MultiSelect = false;

this.points_dataGridView.Name = "points_dataGridView";

this.points_dataGridView.ReadOnly = true;

this.points_dataGridView.RowTemplate.ReadOnly = true;

this.points_dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;

this.points_dataGridView.Size = new System.Drawing.Size(598, 482);

this.points_dataGridView.TabIndex = 0;

//

// TimePassedColumn

//

this.TimePassedColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;

this.TimePassedColumn.HeaderText = "Time passed";

this.TimePassedColumn.Name = "TimePassedColumn";

this.TimePassedColumn.ReadOnly = true;

this.TimePassedColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;

//

// xColumn

//

this.xColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;

this.xColumn.HeaderText = "X";

this.xColumn.Name = "xColumn";

this.xColumn.ReadOnly = true;

this.xColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;

//

// yColumn

//

this.yColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;

this.yColumn.HeaderText = "Y";

this.yColumn.Name = "yColumn";

this.yColumn.ReadOnly = true;

this.yColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;

//

// add_button

//

this.add_button.Location = new System.Drawing.Point(52, 507);

this.add_button.Name = "add_button";

this.add_button.Size = new System.Drawing.Size(165, 23);

this.add_button.TabIndex = 1;

this.add_button.Text = "Добавить новую точку";

this.add_button.UseVisualStyleBackColor = true;

this.add_button.Click += new System.EventHandler(this.add_button_Click);

//

// edit_button

//

this.edit_button.Location = new System.Drawing.Point(223, 507);

this.edit_button.Name = "edit_button";

this.edit_button.Size = new System.Drawing.Size(165, 23);

this.edit_button.TabIndex = 2;

this.edit_button.Text = "Редактировать данные точки";

this.edit_button.UseVisualStyleBackColor = true;

this.edit_button.Click += new System.EventHandler(this.edit_button_Click);

//

// delete_button

//

this.delete_button.Location = new System.Drawing.Point(394, 507);

this.delete_button.Name = "delete_button";

this.delete_button.Size = new System.Drawing.Size(165, 23);

this.delete_button.TabIndex = 3;

this.delete_button.Text = "Удалить текущую точку";

this.delete_button.UseVisualStyleBackColor = true;

this.delete_button.Click += new System.EventHandler(this.delete_button_Click);

//

// points_groupBox

//

this.points_groupBox.Controls.Add(this.points_dataGridView);

this.points_groupBox.Controls.Add(this.delete_button);

this.points_groupBox.Controls.Add(this.add_button);

this.points_groupBox.Controls.Add(this.edit_button);

this.points_groupBox.Location = new System.Drawing.Point(12, 12);

this.points_groupBox.Name = "points_groupBox";

this.points_groupBox.Size = new System.Drawing.Size(615, 540);

this.points_groupBox.TabIndex = 4;

this.points_groupBox.TabStop = false;

this.points_groupBox.Text = "Точки ломаной";

//

// refreshData_button

//

this.refreshData_button.Location = new System.Drawing.Point(64, 558);

this.refreshData_button.Name = "refreshData_button";

this.refreshData_button.Size = new System.Drawing.Size(249, 23);

this.refreshData_button.TabIndex = 5;

this.refreshData_button.Text = "Запросить актуальные данные с сервера";

this.refreshData_button.UseVisualStyleBackColor = true;

this.refreshData_button.Click += new System.EventHandler(this.refreshData_button_Click);

//

// pushToServer_button

//

this.pushToServer_button.Location = new System.Drawing.Point(322, 558);

this.pushToServer_button.Name = "pushToServer_button";

this.pushToServer_button.Size = new System.Drawing.Size(249, 23);

this.pushToServer_button.TabIndex = 6;

this.pushToServer_button.Text = "Отправить данные на сервер";

this.pushToServer_button.UseVisualStyleBackColor = true;

this.pushToServer_button.Click += new System.EventHandler(this.pushToServer_button_Click);

//

// ZigzagEditorForm

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(637, 590);

this.Controls.Add(this.pushToServer_button);

this.Controls.Add(this.refreshData_button);

this.Controls.Add(this.points_groupBox);

this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;

this.MaximizeBox = false;

this.Name = "ZigzagEditorForm";

this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

this.Text = "Редактор точек ломаной";

this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ZigzagEditorForm_FormClosing);

this.VisibleChanged += new System.EventHandler(this.ZigzagEditorForm_VisibleChanged);

((System.ComponentModel.ISupportInitialize)(this.points_dataGridView)).EndInit();

this.points_groupBox.ResumeLayout(false);

this.ResumeLayout(false);

}

#endregion

private System.Windows.Forms.DataGridView points_dataGridView;

private System.Windows.Forms.Button add_button;

private System.Windows.Forms.Button edit_button;

private System.Windows.Forms.Button delete_button;

private System.Windows.Forms.GroupBox points_groupBox;

private System.Windows.Forms.Button refreshData_button;

private System.Windows.Forms.Button pushToServer_button;

private System.Windows.Forms.DataGridViewTextBoxColumn TimePassedColumn;

private System.Windows.Forms.DataGridViewTextBoxColumn xColumn;

private System.Windows.Forms.DataGridViewTextBoxColumn yColumn;

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]