-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathInputComboDialog.cs
69 lines (62 loc) · 2.37 KB
/
InputComboDialog.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TeX2img {
public partial class InputComboDialog : Form {
public string InputedText { get; private set; }
TextBox InputTextBox;
bool isCombo;
public InputComboDialog(string title,string label,List<string> list,string defaultstr = "") {
InitializeComponent();
if(list == null) {
isCombo = false;
InputTextBox = new TextBox() {
Location = InputComboBox.Location,
Size = InputComboBox.Size,
TabIndex = InputComboBox.TabIndex,
Name = "InputTextBox",
};
Controls.Remove(InputComboBox);
Controls.Add(InputTextBox);
InputTextBox.Text = defaultstr;
} else {
isCombo = true;
foreach(var l in list) {
InputComboBox.Items.Add(l);
}
InputComboBox.Text = defaultstr;
}
InputDialogLabel.Text = label;
Text = title;
}
protected override void OnShown(EventArgs e) {
if(isCombo) InputComboBox.Focus();
else InputTextBox.Focus();
base.OnShown(e);
}
private void OKButton_Click(object sender, EventArgs e) {
var text = isCombo ? InputComboBox.Text : InputTextBox.Text;
var ee = new OKButtonClickedEventArgs(text);
OKButtonClicked(this, ee);
if(!ee.Cancel) {
InputedText = text;
DialogResult = System.Windows.Forms.DialogResult.OK;
}
}
private void CancelButton_Click(object sender, EventArgs e) {
DialogResult = System.Windows.Forms.DialogResult.Cancel;
}
public class OKButtonClickedEventArgs : EventArgs{
public bool Cancel = false;
public string InputedText;
public OKButtonClickedEventArgs(string text) { InputedText = text; }
}
public delegate void OKButtonClieckedEventHandler(object sender, OKButtonClickedEventArgs e);
public event OKButtonClieckedEventHandler OKButtonClicked = ((s, e) => { });
}
}