Смекни!
smekni.com

Разработка ПО графического редактора (стр. 2 из 3)


ЗАКЛЮЧЕНИЕ

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

При выполнении курсового проекта были пройдены все этапы разработки специализированного прикладного программного обеспечения:

· формализация задачи;

· сбор необходимых исходных данных, используемых в программе;

· ознакомление с литературой;

· более углубленное изучение платформы .NET

В данном курсовом проекте было разработано визуальное приложение, которое позволяет:

· Открывать графический файл.

· Сохранять графический файл.

· Выводить на печать.

· Изменять страницы печати.

· Изменять размеры графического файла.

Для программы был разработан интерфейс, позволяющий не очень опытному пользователю работать с программой.

В ходе курсового проекта был более детально изучен язык С#, а также использование платформы .NET.

СПИСОК ЛИТЕРАТУРЫ

1. Лабор В.В. – С# Создание приложений для Windows (2003)

2. Шилдт Г. – Полный справочник по C#

3. Эндрю Троелсен - С# и платформа .NET

4. Павловская – Программирование на языке высокого уровня на С#.

5. Фролов А.В. Фролов Г.В. – Язык С#

6. Petzold_Programming_MS_Windows__Sharp_v12


Приложение

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.IO;

using System.Drawing.Printing;

namespace PictureViewer

{

public class Form1 : System.Windows.Forms.Form

{

private System.Windows.Forms.MainMenu mainMenu1;

private System.Windows.Forms.MenuItem menuFile;

private System.Windows.Forms.MenuItem menuOpen;

private System.Windows.Forms.MenuItem menuSave;

private System.Windows.Forms.MenuItem menuItem1;

private System.Windows.Forms.MenuItem menuPageSetup;

private System.Windows.Forms.MenuItem menuPreview;

private System.Windows.Forms.MenuItem menuPrint;

private System.Windows.Forms.MenuItem menuItem5;

private System.Windows.Forms.MenuItem menuExit;

private System.Windows.Forms.MenuItem menuView;

private System.Windows.Forms.MenuItem menuResize;

private System.Windows.Forms.OpenFileDialog openFileDialog1;

private System.Windows.Forms.SaveFileDialog saveFileDialog1;

private System.Windows.Forms.ContextMenu contextMenu1;

private System.Windows.Forms.PictureBox pictureBox1;

private System.Windows.Forms.MenuItem menuBase;

private System.Windows.Forms.MenuItem menuCenterImage;

private System.Windows.Forms.MenuItem menuAutoSize;

private System.Windows.Forms.MenuItem cmenuResize;

private System.Windows.Forms.MenuItem cmenuBase;

private System.Windows.Forms.MenuItem cmenuCenterImage;

private System.Windows.Forms.MenuItem cmenuAutoSize;

private System.Windows.Forms.StatusBar statusBar1;

private System.Windows.Forms.StatusBarPanel sbFile;

private System.Windows.Forms.StatusBarPanel sbSize;

private System.Windows.Forms.PrintDialog printDialog1;

private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;

private System.Windows.Forms.PageSetupDialog pageSetupDialog1;

private System.Drawing.Printing.PrintDocument printDocument1;

private IContainer components;

public Form1()

{

InitializeComponent();

}

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));

this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);

this.menuFile = new System.Windows.Forms.MenuItem();

this.menuOpen = new System.Windows.Forms.MenuItem();

this.menuSave = new System.Windows.Forms.MenuItem();

this.menuItem1 = new System.Windows.Forms.MenuItem();

this.menuPageSetup = new System.Windows.Forms.MenuItem();

this.menuPreview = new System.Windows.Forms.MenuItem();

this.menuPrint = new System.Windows.Forms.MenuItem();

this.menuItem5 = new System.Windows.Forms.MenuItem();

this.menuExit = new System.Windows.Forms.MenuItem();

this.menuView = new System.Windows.Forms.MenuItem();

this.menuResize = new System.Windows.Forms.MenuItem();

this.menuBase = new System.Windows.Forms.MenuItem();

this.menuCenterImage = new System.Windows.Forms.MenuItem();

this.menuAutoSize = new System.Windows.Forms.MenuItem();

this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

this.contextMenu1 = new System.Windows.Forms.ContextMenu();

this.cmenuResize = new System.Windows.Forms.MenuItem();

this.cmenuBase = new System.Windows.Forms.MenuItem();

this.cmenuCenterImage = new System.Windows.Forms.MenuItem();

this.cmenuAutoSize = new System.Windows.Forms.MenuItem();

this.pictureBox1 = new System.Windows.Forms.PictureBox();

this.statusBar1 = new System.Windows.Forms.StatusBar();

this.sbFile = new System.Windows.Forms.StatusBarPanel();

this.sbSize = new System.Windows.Forms.StatusBarPanel();

this.printDialog1 = new System.Windows.Forms.PrintDialog();

this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();

this.pageSetupDialog1 = new System.Windows.Forms.PageSetupDialog();

this.printDocument1 = new System.Drawing.Printing.PrintDocument();

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

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

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

this.SuspendLayout();

// mainMenu1

this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuFile,

this.menuView});

// menuFile

this.menuFile.Index = 0;

this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuOpen,

this.menuSave,

this.menuItem1,

this.menuPageSetup,

this.menuPreview,

this.menuPrint,

this.menuItem5,

this.menuExit});

this.menuFile.Text = "&Файл";

this.menuFile.Click += new System.EventHandler(this.menuFile_Click);

// menuOpen

this.menuOpen.Index = 0;

this.menuOpen.Shortcut = System.Windows.Forms.Shortcut.CtrlO;

this.menuOpen.Text = "&Открыть";

this.menuOpen.Click += new System.EventHandler(this.menuOpen_Click);

// menuSave

this.menuSave.Index = 1;

this.menuSave.Shortcut = System.Windows.Forms.Shortcut.CtrlS;

this.menuSave.Text = "&Сохранить";

this.menuSave.Click += new System.EventHandler(this.menuSave_Click);

// menuItem1

this.menuItem1.Index = 2;

this.menuItem1.Text = "-";

// menuPageSetup

this.menuPageSetup.Index = 3;

this.menuPageSetup.Text = "Параметры Стра&ницы";

this.menuPageSetup.Click += new System.EventHandler(this.menuPageSetup_Click);

// menuPreview

this.menuPreview.Index = 4;

this.menuPreview.Text = "Предварительный просм&отр ";

this.menuPreview.Click += new System.EventHandler(this.menuPreview_Click);

// menuPrint

this.menuPrint.Index = 5;

this.menuPrint.Shortcut = System.Windows.Forms.Shortcut.CtrlP;

this.menuPrint.Text = "&Печать";

this.menuPrint.Click += new System.EventHandler(this.menuPrint_Click);

// menuItem5

this.menuItem5.Index = 6;

this.menuItem5.Text = "-";

// menuExit

this.menuExit.Index = 7;

this.menuExit.Shortcut = System.Windows.Forms.Shortcut.AltF4;

this.menuExit.Text = "&Выход";

this.menuExit.Click += new System.EventHandler(this.menuExit_Click);

// menuView

this.menuView.Index = 1;

this.menuView.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuResize,

this.menuBase,

this.menuCenterImage,

this.menuAutoSize});

this.menuView.Text = "&Вид";

this.menuView.Popup += new System.EventHandler(this.menuView_Popup);

this.menuView.Click += new System.EventHandler(this.menuView_Click);

// menuResize

this.menuResize.Index = 0;

this.menuResize.Text = "&Растянутьнавсёокно";

this.menuResize.Click += new System.EventHandler(this.menuResize_Click);

// menuBase

this.menuBase.Index = 1;

this.menuBase.Text = "&Исходный размер";

this.menuBase.Click += new System.EventHandler(this.menuBase_Click);

// menuCenterImage

this.menuCenterImage.Index = 2;

this.menuCenterImage.Text = "&Центрировать";

this.menuCenterImage.Click += new System.EventHandler(this.menuCenterImage_Click);

// menuAutoSize

this.menuAutoSize.Index = 3;

this.menuAutoSize.Text = "&Поумолчанию";

this.menuAutoSize.Click += new System.EventHandler(this.menuAutoSize_Click);

// openFileDialog1

this.openFileDialog1.Title = "Выборизображения";

// saveFileDialog1

this.saveFileDialog1.Title = "Сохранениеизображения";

// contextMenu1

this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.cmenuResize,

this.cmenuBase,

this.cmenuCenterImage,

this.cmenuAutoSize});

// cmenuResize

this.cmenuResize.Index = 0;

this.cmenuResize.Text = "&Растянутьнавсёокно";

this.cmenuResize.Click += new System.EventHandler(this.cmenuResize_Click);

// cmenuBase

this.cmenuBase.Index = 1;

this.cmenuBase.Text = "&Исходный размер";

this.cmenuBase.Click += new System.EventHandler(this.cmenuBase_Click);

// cmenuCenterImage

this.cmenuCenterImage.Index = 2;

this.cmenuCenterImage.Text = "&Центрировать";

this.cmenuCenterImage.Click += new System.EventHandler(this.cmenuCenterImage_Click);

// cmenuAutoSize

this.cmenuAutoSize.Index = 3;

this.cmenuAutoSize.Text = "&Поумолчанию";

this.cmenuAutoSize.Click += new System.EventHandler(this.cmenuAutoSize_Click);

// pictureBox1

this.pictureBox1.ContextMenu = this.contextMenu1;

this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;

this.pictureBox1.Location = new System.Drawing.Point(0, 0);

this.pictureBox1.Name = "pictureBox1";

this.pictureBox1.Size = new System.Drawing.Size(616, 266);

this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;

this.pictureBox1.TabIndex = 0;

this.pictureBox1.TabStop = false;

// statusBar1

this.statusBar1.Location = new System.Drawing.Point(0, 244);

this.statusBar1.Name = "statusBar1";

this.statusBar1.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {

this.sbFile,

this.sbSize});

this.statusBar1.ShowPanels = true;

this.statusBar1.Size = new System.Drawing.Size(616, 22);

this.statusBar1.TabIndex = 3;

// sbFile

this.sbFile.Name = "sbFile";

this.sbFile.Width = 500;

// sbSize

this.sbSize.Name = "sbSize";

// printPreviewDialog1

this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);

this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);

this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);

this.printPreviewDialog1.Enabled = true;

this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));

this.printPreviewDialog1.Name = "printPreviewDialog1";

this.printPreviewDialog1.Visible = false;

// printDocument1

this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);

// Form1

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);

this.ClientSize = new System.Drawing.Size(616, 266);

this.ContextMenu = this.contextMenu1;

this.Controls.Add(this.statusBar1);

this.Controls.Add(this.pictureBox1);

this.Menu = this.mainMenu1;

this.Name = "Form1";

this.Text = "Picture Viewer";

this.Load += new System.EventHandler(this.Form1_Load);

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

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

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

this.ResumeLayout(false);

}

#endregion

private PictureBoxSizeMode[] ArrayMenu =

{

PictureBoxSizeMode.StretchImage,

PictureBoxSizeMode.Normal,

PictureBoxSizeMode.CenterImage,

PictureBoxSizeMode.AutoSize

};

private int selectedMode = 0;

[STAThread]

static void Main()

{

Application.Run(new Form1());

}

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

{

OpenFileDialog diag = new OpenFileDialog();

diag.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*" ;

if (diag.ShowDialog() == DialogResult.OK)

{

pictureBox1.Image = new Bitmap(diag.OpenFile());

}

sbFile.Text = "Загрузка " + diag.FileName;

sbFile.Text = "Изображение " + diag.FileName;

sbSize.Text= String.Format("{0:#} x {1:#}", pictureBox1.Image.Width, pictureBox1.Image.Height);

}

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

{

SaveFileDialog diag = new SaveFileDialog();

diag.Filter = "jpg files (*.jpg)|*.jpg|All files (*.*)|*.*" ;

if(diag.ShowDialog() != DialogResult.OK)

return;

string filename = diag.FileName;

FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite);

pictureBox1.Image.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);

fs.Close();

}

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

{

this.Close();

}

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

{

if (sender is MenuItem)

{

MenuItem menuitem = (MenuItem)sender;

selectedMode = menuitem.Index;

pictureBox1.SizeMode = ArrayMenu[0];

pictureBox1.Invalidate();

}

}

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

{

if (sender is MenuItem)

{

MenuItem menuitem = (MenuItem)sender;

selectedMode = menuitem.Index;

pictureBox1.SizeMode = ArrayMenu[1];

pictureBox1.Invalidate();

}

}

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

{

if (sender is MenuItem)

{

bool ImLoad = (pictureBox1.Image != null);

foreach (MenuItem menuitem in ((MenuItem)sender).MenuItems)

{

menuitem.Enabled = ImLoad;

menuitem.Checked = (this.selectedMode == menuitem.Index);

}

}

}

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

{

if (sender is MenuItem)