1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
| #pragma once
namespace ТаблВвод {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Сводка для Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: добавьте код конструктора
//
}
protected:
/// <summary>
/// Освободить все используемые ресурсы.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::DataGridView^ dataGridView1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Panel^ panel1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Panel^ panel2;
private: System::Windows::Forms::DataVisualization::Charting::Chart^ chart1;
private: System::Windows::Forms::MenuStrip^ menuStrip1;
private: System::Windows::Forms::ToolStripMenuItem^ выходToolStripMenuItem;
private: System::Windows::Forms::ListBox^ listBox1;
private: System::Windows::Forms::Button^ button3;
private: Microsoft::VisualBasic::PowerPacks::ShapeContainer^ shapeContainer1;
private: Microsoft::VisualBasic::PowerPacks::RectangleShape^ rectangleShape1;
private:
/// <summary>
/// Требуется переменная конструктора.
/// </summary>
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
/// Обязательный метод для поддержки конструктора - не изменяйте
/// содержимое данного метода при помощи редактора кода.
/// </summary>
void InitializeComponent(void)
{
System::Windows::Forms::DataVisualization::Charting::ChartArea^ chartArea3 = (gcnew System::Windows::Forms::DataVisualization::Charting::ChartArea());
System::Windows::Forms::DataVisualization::Charting::Legend^ legend3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Legend());
System::Windows::Forms::DataVisualization::Charting::Series^ series3 = (gcnew System::Windows::Forms::DataVisualization::Charting::Series());
this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
this->button1 = (gcnew System::Windows::Forms::Button());
this->panel1 = (gcnew System::Windows::Forms::Panel());
this->button3 = (gcnew System::Windows::Forms::Button());
this->listBox1 = (gcnew System::Windows::Forms::ListBox());
this->button2 = (gcnew System::Windows::Forms::Button());
this->panel2 = (gcnew System::Windows::Forms::Panel());
this->chart1 = (gcnew System::Windows::Forms::DataVisualization::Charting::Chart());
this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
this->выходToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
this->shapeContainer1 = (gcnew Microsoft::VisualBasic::PowerPacks::ShapeContainer());
this->rectangleShape1 = (gcnew Microsoft::VisualBasic::PowerPacks::RectangleShape());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->BeginInit();
this->panel1->SuspendLayout();
this->panel2->SuspendLayout();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->chart1))->BeginInit();
this->menuStrip1->SuspendLayout();
this->SuspendLayout();
//
// dataGridView1
//
this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
this->dataGridView1->Location = System::Drawing::Point(12, 19);
this->dataGridView1->Name = L"dataGridView1";
this->dataGridView1->Size = System::Drawing::Size(218, 213);
this->dataGridView1->TabIndex = 0;
//
// button1
//
this->button1->Location = System::Drawing::Point(83, 238);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(103, 23);
this->button1->TabIndex = 1;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// panel1
//
this->panel1->Controls->Add(this->button3);
this->panel1->Controls->Add(this->listBox1);
this->panel1->Controls->Add(this->button2);
this->panel1->Controls->Add(this->dataGridView1);
this->panel1->Controls->Add(this->button1);
this->panel1->Controls->Add(this->shapeContainer1);
this->panel1->Dock = System::Windows::Forms::DockStyle::Bottom;
this->panel1->Location = System::Drawing::Point(0, 326);
this->panel1->Name = L"panel1";
this->panel1->Size = System::Drawing::Size(431, 271);
this->panel1->TabIndex = 2;
//
// button3
//
this->button3->Location = System::Drawing::Point(324, 167);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 23);
this->button3->TabIndex = 5;
this->button3->Text = L"button3";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// listBox1
//
this->listBox1->FormattingEnabled = true;
this->listBox1->Location = System::Drawing::Point(279, 66);
this->listBox1->Name = L"listBox1";
this->listBox1->Size = System::Drawing::Size(120, 95);
this->listBox1->TabIndex = 3;
this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::listBox1_SelectedIndexChanged);
//
// button2
//
this->button2->Location = System::Drawing::Point(324, 19);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 2;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// panel2
//
this->panel2->Controls->Add(this->chart1);
this->panel2->Dock = System::Windows::Forms::DockStyle::Fill;
this->panel2->Location = System::Drawing::Point(0, 24);
this->panel2->Name = L"panel2";
this->panel2->Size = System::Drawing::Size(431, 302);
this->panel2->TabIndex = 3;
//
// chart1
//
chartArea3->Name = L"ChartArea1";
this->chart1->ChartAreas->Add(chartArea3);
this->chart1->Dock = System::Windows::Forms::DockStyle::Fill;
legend3->Name = L"Legend1";
this->chart1->Legends->Add(legend3);
this->chart1->Location = System::Drawing::Point(0, 0);
this->chart1->Name = L"chart1";
series3->ChartArea = L"ChartArea1";
series3->Legend = L"Legend1";
series3->Name = L"Series1";
this->chart1->Series->Add(series3);
this->chart1->Size = System::Drawing::Size(431, 302);
this->chart1->TabIndex = 0;
this->chart1->Text = L"chart1";
this->chart1->Click += gcnew System::EventHandler(this, &Form1::chart1_Click);
//
// menuStrip1
//
this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->выходToolStripMenuItem});
this->menuStrip1->Location = System::Drawing::Point(0, 0);
this->menuStrip1->Name = L"menuStrip1";
this->menuStrip1->Size = System::Drawing::Size(431, 24);
this->menuStrip1->TabIndex = 4;
this->menuStrip1->Text = L"menuStrip1";
//
// выходToolStripMenuItem
//
this->выходToolStripMenuItem->Name = L"выходToolStripMenuItem";
this->выходToolStripMenuItem->Size = System::Drawing::Size(53, 20);
this->выходToolStripMenuItem->Text = L"Выход";
this->выходToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::выходToolStripMenuItem_Click);
//
// shapeContainer1
//
this->shapeContainer1->Location = System::Drawing::Point(0, 0);
this->shapeContainer1->Margin = System::Windows::Forms::Padding(0);
this->shapeContainer1->Name = L"shapeContainer1";
this->shapeContainer1->Shapes->AddRange(gcnew cli::array< Microsoft::VisualBasic::PowerPacks::Shape^ >(1) {this->rectangleShape1});
this->shapeContainer1->Size = System::Drawing::Size(431, 271);
this->shapeContainer1->TabIndex = 4;
this->shapeContainer1->TabStop = false;
//
// rectangleShape1
//
this->rectangleShape1->Location = System::Drawing::Point(352, 218);
this->rectangleShape1->Name = L"rectangleShape1";
this->rectangleShape1->Size = System::Drawing::Size(44, 36);
this->rectangleShape1->Click += gcnew System::EventHandler(this, &Form1::rectangleShape1_Click);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(431, 597);
this->Controls->Add(this->panel2);
this->Controls->Add(this->panel1);
this->Controls->Add(this->menuStrip1);
this->MainMenuStrip = this->menuStrip1;
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->dataGridView1))->EndInit();
this->panel1->ResumeLayout(false);
this->panel2->ResumeLayout(false);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->chart1))->EndInit();
this->menuStrip1->ResumeLayout(false);
this->menuStrip1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
DataTable ^ Таблица; // Объявление объекта "таблица данных"
DataSet ^ НаборДанных; // Объявление объекта "набор данных"
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
this->Text = "Почти табличный редактор";
button1->Text = "Запись";
Таблица = gcnew DataTable();
НаборДанных = gcnew DataSet();
if (IO::File::Exists("F:\\tabl.xml") == false)
{
// Если XML-файла НЕТ:
dataGridView1->DataSource = Таблица;
// Заполнение "шапки" таблицы
Таблица->Columns->Add("Название");
Таблица->Columns->Add("Данные");
// Добавить объект Таблица в DataSet
НаборДанных->Tables->Add(Таблица);
}
else // Если XML-файл ЕCТЬ:
{
НаборДанных->ReadXml("F:\\tabl.xml");
// Содержимое DataSet в виде строки XML для отладки:
String ^ СтрокаXML = НаборДанных->GetXml();
dataGridView1->DataMember = "Название таблицы";
dataGridView1->DataSource = НаборДанных;
}
// Получаем массив строк имен цветов из перечисления KnownColor.
// Enum::GetNames возвращает массив имен констант
// в указанном перечислении:
array<String^>^ ВсеЦвета = Enum::GetNames(KnownColor::typeid);
// Удаление всех элементов из коллекции:
listBox1->Items->Clear();
// Добавляем имена всех цветов в список listBox1:
for each (String^ s in ВсеЦвета)
if (s != "Transparent") listBox1->Items->Add(s);
// Цвет Transparent является "прозрачным",
// он не поддерживается для формы
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
// Сохранить файл tabl.xml:
Таблица->TableName = "Название таблицы";
НаборДанных->WriteXml("F:\\tabl.xml");
}
private: System::Void выходToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e)
{
Application::Exit();
}
private: System::Void chart1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e)
{
// Составленную таблицу указываем в качестве источника данных:
chart1->DataSource = НаборДанных;
// По горизонтальной оси откладываем названия:
chart1->Series["Series1"]->XValueMember = "Название";
// А по вертикольной оси откладываем данные:
chart1->Series["Series1"]->YValueMembers = "Данные";
// Задаем тип диаграммы - столбиковая гистограмма:
chart1->Series["Series1"]->ChartType = System::Windows::Forms::DataVisualization::Charting::SeriesChartType::Column;
// Тип диаграммы может быыть другим, например: Pie, Line и др.
chart1->Series["Series1"]->Color = Color::FromName(listBox1->Text);
// Легенду на графике не отображаем:
chart1->Series["Series1"]->IsVisibleInLegend = false;
// Приязка графика к источнику данных:
chart1->DataBind();
// Для сетки данных указываем источник данных
dataGridView1->DataSource = Таблица;
}
private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e)
{
// Обработка события изменения выбранного
// индекса в списке listBox1:
// Надпись в строке заголовка формы:
this->Text = "Цвет: " + listBox1->Text;
}
private: System::Void rectangleShape1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e)
{
//this->BackColor = Color::FromName(listBox1->Text);
}
};
} |