Чтение онлайн

ЖАНРЫ

Интернет-журнал "Домашняя лаборатория", 2007 №9
Шрифт:

/// процедуры:

/// Set_Item: Linkable*T —> Linkable

/// Set_Next: Linkable*Linkable —> Linkable

/// Роль типа T играет Figure

/// </summary>

public class Linkable

{

public Linkable

{

item =null; next = null;

}

/// <summary>

/// закрытые атрибуты класса

/// </summary>

Figure item;

Linkable next;

/// <summary>

/// процедуры свойства для доступа к полям класса

/// </summary>

public Figure Item {

get {

return(item);

}

set {

item = value;

}

}

public Linkable Next {

get {

return(next);

}

set {

next = value;

}

}

}//class Linkable

/// <summary>

///

Класс TwoLinkable задает элементы с двумя ссылками

/// </summary>

public class TwoLinkable

{

public TwoLinkable

{

prev = next = null;

}

/// <summary>

/// закрытые атрибуты класса

/// </summary>

TwoLinkable prev, next;

Figure item;

/// <summary>

/// процедуры свойства для доступа к полям класса

/// </summary>

public Figure Item

{

get

{

return(item);

}

set

{

item = value;

}

}

public TwoLinkable Next

{

get

{

return(next);

}

set

{

next = value;

}

}

public TwoLinkable Prev

{

get

{

return(prev);

}

set

{

prev = value;

}

}

}//class TwoLinkable

}

Организация интерфейса

Создадим теперь интерфейс, позволяющий конечному пользователю работать с объектами наших классов. Как всегда, интерфейс создавался вручную в режиме проектирования. На форме я создал меню с большим числом команд и инструментальную панель с 18 кнопками, команды которых повторяли основную команду меню. Описывать процесс создания интерфейса не буду — он подробно рассмотрен в предыдущей главе. Поскольку вся работа по созданию интерфейса транслируется в программный код формы, то просто приведу этот достаточно длинный текст почти без всяких купюр:

using System;

using System.Drawing;

using System.Collections;

using System.ComponentMode1;

using System.Windows.Forms;

using System.Data;

using Shapes;

namespace Final

{

/// <summary>

/// Эта форма обеспечивает интерфейс для создания,

/// рисования, показа, перемещения, сохранения в списке

/// и выполнения других операций над объектами семейства

/// геометрических фигур. Форма имеет меню и

/// инструментальные панели.

/// </summary>

public class Form1 System.Windows.Forms.Form

{

//fields

Graphics graphic;

Brush brush, clearBrush;

Pen pen, clearPen;

Color color;

Figure current;

TwoWayList listFigure;

private System.Windows.Forms.MainMenu mainMenu1

private System.Windows.Forms.ImageList imageList1;

private System.Windows.Forms.ToolBar tooiBar1

private System.Windows.Forms.MenuItem menuItem1

//

аналогичные определения для других элементов меню

private System.Windows.Forms.MenuItem menuItem35;

private System.Windows.Forms.ToolBarButton toolBarButton1;

// аналогичные определения для других командных кнопок

private System.Windows.Forms.ToolBarButton toolBarButton18;

private System.ComponentMode1.IContainer components;

public Form1

{

InitializeComponent ;

InitFields;

}

void InitFields

{

graphic = CreateGraphics ;

color = SystemColors.ControlText;

brush = new SolidBrush(color);

clearBrush = new SolidBrush(SystemColors.Control);

pen = new Pen (color);

clearPen = new Pen(SystemColors.Control);

listFigure = new TwoWayList;

current = new Person (20, 50, 50);

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose(bool disposing)

{

if(disposing)

{

if (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

{

// Код, инициализирующий компоненты и построенный

// дизайнером, опущен

}

#endregion

/// <summary>

/// Точка входа в приложение — процедура Main,

/// запускающая форму

/// </summary>

[STAThread]

static void Main

{

Application.Run(new Form1);

}

private void menuItem7_Click(object sender, System.EventArgs e)

{

createEllipse ;

}

void createEllipse

{

//clear old figure

if (current!= null) current.Show(graphic, clearPen, clearBrush);

//create ellipse

current = new Ellipse (50, 30, 180,180);

}

private void menuItem8_Click(object sender, System.EventArgs e)

{

createCircle ;

}

void createCircle

{

//clear old figure

if (current!= null) current.Show(graphic, clearPen, clearBrush);

//create circle

current = new Circle (30, 180, 180);

}

private void menuItem9_Click(object sender, System.EventArgs e)

{

createLittleCircle ;

Поделиться с друзьями: