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

Листинг(16):

private void button2_Click(object sender, EventArgs e)

{

String[] Имена = { "Имена",

"Даулет", "Вован", "Макс",

"Абай", "Лёха",

"Игорёк", "Mr.Ed",

"Санjик", "Нохча"};

String[] Восточные_танцы = { "Восточные_танцы",

"28", "5",

"55", "45", "30",

"40", "50",

"70", "100"};

String[] Сталеварение = { "Сталеварение",

"90", "60",

"20", "5", "25",

"66", "90",

"50", "100"};

var Ворд1 = new Microsoft.Office.Interop.Word.Application();

Ворд1.Visible = true;

var Документ = Ворд1.Documents.Add();

Ворд1.Selection.TypeText("Список успеваемости по предметам (в баллах от 0 до 100)");

var t1 = Microsoft.Office.Interop.Word.WdDefaultTableBehavior.wdWord9TableBehavior;

var t2 = Microsoft.Office.Interop.Word.WdAutoFitBehavior.wdAutoFitContent;

Ворд1.ActiveDocument.Tables.Add(Ворд1.Selection.Range, 10, 3, t1, t2);

for (int i = 1; i <= 10; i++)

{

Ворд1.ActiveDocument.Tables[1].Cell(i, 1).Range.InsertAfter(Имена[i - 1]);

Ворд1.ActiveDocument.Tables[1].Cell(i, 2).Range.InsertAfter(Восточные_танцы[i - 1]);

Ворд1.ActiveDocument.Tables[1].Cell(i, 3).Range.InsertAfter(Сталеварение[i - 1]);

}

var t3 = Microsoft.Office.Interop.Word.WdUnits.wdLine;

var Строка9 = 10;

Ворд1.Selection.MoveDown(t3, Строка9, null);

Ворд1.Selection.TypeText("Dageštan™");

}

}

}

Контрольный пример(16):

Описание программы № 16:

Поиск в текстовом файле

Листинг(16):

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using System.IO;

namespace WindowsFormsApplication9

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{

Stream myStream;

if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)

{

if ((myStream = openFileDialog1.OpenFile()) != null)

{

string strfilename = openFileDialog1.FileName;

string filetext = File.ReadAllText(strfilename);

richTextBox1.Text = filetext;

}

}

}

private void button2_Click(object sender, EventArgs e)

{

int index = 0;

string temp = richTextBox1.Text;

richTextBox1.Text = "";

richTextBox1.Text = temp;

while(index < richTextBox1.Text.LastIndexOf(textBox1.Text))

{

richTextBox1.Find(textBox1.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);

richTextBox1.SelectionBackColor = Color.Pink;

index = richTextBox1.Text.IndexOf(textBox1.Text, index) + 1;

}

}

private void Form1_Load(object sender, EventArgs e)

{

this.Text = "Поиск";

button1.Text = "Загрузка файла";

button2.Text = "Поиск";

}

}

}