Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
ОПИ7.docx
Скачиваний:
17
Добавлен:
07.02.2016
Размер:
491.24 Кб
Скачать

2. Текст програми:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace Task2

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private string[] pFileNames;

private int pCurrentImage;

private int n;

private void ShowCurrentImage()

{

if (pCurrentImage >= 0)

{

pictureBox1.Image = Bitmap.FromFile(pFileNames[pCurrentImage]);

}

}

private void button1_Click(object sender, EventArgs e)

{

if (pFileNames.Length > 0)

{

pCurrentImage = pCurrentImage == 0 ? pFileNames.Length - 1 : --pCurrentImage;

textBox1.Text = pFileNames[pCurrentImage];

ShowCurrentImage();

}

}

private void button2_Click(object sender, EventArgs e)

{

if (pFileNames.Length > 0)

{

pCurrentImage = pCurrentImage == pFileNames.Length - 1 ? 0 : ++pCurrentImage;

int n = pFileNames.Length;

textBox1.Text = pFileNames[pCurrentImage];

ShowCurrentImage();

}

}

private void button3_Click(object sender, EventArgs e)

{

OpenFileDialog openFileDialog1 = new OpenFileDialog();

openFileDialog1.Multiselect = true;

openFileDialog1.Filter = "JPEG (*.jpg,*.jpeg,*.jpe,*.jfif)|*.jpg;*.jpeg;*.jpe;*.jfif|PNG (*.png)|*.png|ICO (*.ico)|*.ico|TIFF (*.tif,*.tiff)|*.tif;*.tiff|GIF (*.gif)|*.gif";

openFileDialog1.FilterIndex = 1;

openFileDialog1.RestoreDirectory = true;

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

{

pFileNames = openFileDialog1.FileNames;

button2.Enabled = true;

button1.Enabled = true;

pCurrentImage = 0;

textBox1.Text = pFileNames[0];

listBox1.Items.Clear();

n = pFileNames.Length;

for (int i = 0; i < n; i++)

{

listBox1.Items.Add(pFileNames[i]);

}

if (listBox1.Items.Count == 0) { }

else

{

listBox1.SelectedIndex = 0;

}

ShowCurrentImage();

}

}

private void button4_Click(object sender, EventArgs e)

{

listBox1.Items.Clear();

textBox1.Text = "";

button2.Enabled = false;

button1.Enabled = false;

pFileNames = null;

pictureBox1.Image = null;

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{

pCurrentImage = listBox1.SelectedIndex;

textBox1.Text = pFileNames[pCurrentImage];

ShowCurrentImage();

}

}

}

На рис. 1.2 зображені результати роботи програми:

Рисунок 1.2 – Робота програми

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