-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGoToLineDialog.cs
More file actions
95 lines (81 loc) · 3.4 KB
/
Copy pathGoToLineDialog.cs
File metadata and controls
95 lines (81 loc) · 3.4 KB
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
using System;
using System.Drawing;
using System.Windows.Forms;
namespace Yotepad
{
public class GoToLineDialog : Form
{
private TextBox _txtLineNumber = new TextBox();
private Button _btnGoTo = new Button();
private Button _btnCancel = new Button();
private Label _lblPrompt = new Label();
public int LineNumber { get; private set; } = -1;
public GoToLineDialog(ThemeManager themeManager, int currentLine, int maxLine)
{
InitializeComponent(currentLine, maxLine);
ApplyTheme(themeManager);
}
private void InitializeComponent(int currentLine, int maxLine)
{
this.Text = "Go To Line";
this.ClientSize = new Size(280, 110);
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = FormStartPosition.CenterParent;
_lblPrompt.Text = $"Line number (1 - {maxLine}):";
_lblPrompt.Location = new Point(12, 15);
_lblPrompt.AutoSize = true;
_txtLineNumber.Text = currentLine.ToString();
_txtLineNumber.Location = new Point(12, 38);
_txtLineNumber.Size = new Size(252, 23);
_txtLineNumber.SelectAll();
_btnGoTo.Text = "Go To";
_btnGoTo.Size = new Size(80, 28);
_btnGoTo.Location = new Point(103, 72);
_btnGoTo.Click += (s, e) =>
{
if (int.TryParse(_txtLineNumber.Text, out int line) && line >= 1 && line <= maxLine)
{
LineNumber = line;
this.DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show($"Please enter a number between 1 and {maxLine}.",
"YotePad", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
};
_btnCancel.Text = "Cancel";
_btnCancel.Size = new Size(80, 28);
_btnCancel.Location = new Point(189, 72);
_btnCancel.Click += (s, e) => this.DialogResult = DialogResult.Cancel;
this.Controls.Add(_lblPrompt);
this.Controls.Add(_txtLineNumber);
this.Controls.Add(_btnGoTo);
this.Controls.Add(_btnCancel);
this.AcceptButton = _btnGoTo;
this.CancelButton = _btnCancel;
}
public void ApplyTheme(ThemeManager theme)
{
this.BackColor = theme.BackgroundColor;
this.ForeColor = theme.TextColor;
_txtLineNumber.BackColor = theme.BackgroundColor;
_txtLineNumber.ForeColor = theme.TextColor;
_txtLineNumber.BorderStyle = BorderStyle.FixedSingle;
_lblPrompt.BackColor = theme.BackgroundColor;
_lblPrompt.ForeColor = theme.TextColor;
Button[] buttons = { _btnGoTo, _btnCancel };
foreach (var btn in buttons)
{
btn.FlatStyle = FlatStyle.Flat;
btn.FlatAppearance.BorderColor = Color.DimGray;
btn.BackColor = theme.BackgroundColor;
btn.ForeColor = theme.TextColor;
}
}
}
}