-
Notifications
You must be signed in to change notification settings - Fork 1
/
frmSettings.cs
82 lines (64 loc) · 2.23 KB
/
frmSettings.cs
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
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace MemeGen
{
public partial class frmSettings : Form
{
List<StepControl> steps = new List<StepControl>();
public frmSettings()
{
InitializeComponent();
AddStep();
}
private void btnAddNew_Click(object sender, EventArgs e) => AddStep();
private void AddStep()
{
StepControl step = new StepControl((ushort)steps.Count);
RowStyle style = new RowStyle(SizeType.AutoSize);
if (steps.Count > 0)
{
tableSteps.RowCount += 1;
tableSteps.RowStyles.Add(style);
}
else
tableSteps.RowStyles[0] = style;
tableSteps.Controls.Add(step, 0, steps.Count);
steps.Add(step);
if (steps.Count == ushort.MaxValue)
btnAddNew.Visible = false;
btnRemoveLast.Visible = true;
}
private void btnRemoveLast_Click(object sender, EventArgs e)
{
StepControl step = steps[steps.Count - 1];
tableSteps.Controls.Remove(step);
tableSteps.RowStyles.RemoveAt(tableSteps.RowStyles.Count - 1);
tableSteps.RowCount -= 1;
steps.Remove(step);
if (steps.Count == 1)
btnRemoveLast.Visible = false;
btnAddNew.Visible = true;
}
private void btnGenerate_Click(object sender, EventArgs e)
{
frmMeme f;
List<(Image, string)> extractedSteps = new List<(Image, string)>();
foreach (StepControl step in steps)
{
Image image;
try { image = Image.FromFile(step.ImagePath); }
catch (Exception ex)
{
MessageBox.Show("Error loading image", $"Error loading image {step.ImagePath}: {ex.Message}", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
extractedSteps.Add((image, step.Caption));
}
f = new frmMeme(extractedSteps);
f.ShowDialog();
}
}
}