-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMessageForm.cs
155 lines (137 loc) · 4.64 KB
/
MessageForm.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace NFL2K5Tool
{
public partial class MessageForm : Form
{
/// <summary>
/// Raised when user doubleClicks in the textbox
/// </summary>
public event EventHandler TextClicked;
public MessageForm(Icon icon)
{
InitializeComponent();
this.Icon = icon;
mTextBox.StatusControl = this.mStatusLabel;
}
public bool ShowCancelButton
{
set { this.mCancelButton.Visible = value; }
}
public bool MessageEditable
{
get { return !mTextBox.ReadOnly; }
set { mTextBox.ReadOnly = !value; }
}
/// <summary>
/// sets the text on the Aux button.
/// Aux button returns a dialog result of 'Abort'
/// </summary>
public string AuxButtonText
{
get { return mAuxButton.Text; }
set
{
mAuxButton.Text = value;
mAuxButton.Visible = (mAuxButton.Text.Length > 0);
}
}
/// <summary>
/// The text to show
/// </summary>
public string MessageText
{
get { return mTextBox.Text; }
set { mTextBox.Text = value; }
}
private void mOkButton_Click(object sender, EventArgs e)
{
if (!this.Modal)
Close();
}
private void mTextBox_DoubleClick(object sender, EventArgs e)
{
if (TextClicked != null)
{
this.TextClicked(this, new StringEventArgs(mTextBox.GetCurrentLine()));
}
}
/// <summary>
/// Get a string from the user.
/// </summary>
/// <param name="title">The title of the dialog</param>
/// <param name="message">The initial message to display.</param>
/// <returns>valid string when the user hits 'ok', null when they cancel.</returns>
public static string GetString(string title, string message)
{
return ShowMessage(title, message, SystemIcons.Question, true, true);
}
/// <summary>
/// Returns the MessageText of the Form
/// </summary>
/// <param name="title">The title bar text</param>
/// <param name="message">The initial message text to display</param>
/// <param name="icon">the Icon to use</param>
/// <param name="editable">true to allow the user to edit the MessageText</param>
/// <returns>The resulting MessageText</returns>
public static string ShowMessage(string title, string message, Icon icon, bool editable, bool showCancelButton)
{
string retVal = null;
MessageForm mf = new MessageForm(icon);
mf.MessageEditable = editable;
mf.Text = title;
mf.MessageText = message;
mf.ShowCancelButton = showCancelButton;
if (mf.ShowDialog() == DialogResult.OK)
{
retVal = mf.MessageText;
}
mf.Dispose();
return retVal;
}
/// <summary>
/// Shows a message
/// </summary>
/// <param name="title">the title bar text</param>
/// <param name="message">the message to show</param>
public static void ShowMessage(string title, string message)
{
ShowMessage(title, message, SystemIcons.Information, false, false);
}
private void mTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.LinkText);
}
public void Colorize(Regex reg, Color color)
{
mTextBox.Visible = false;
mTextBox.SelectionLength = 0;
MatchCollection mc = reg.Matches(mTextBox.Text);
foreach (Match m in mc)
{
mTextBox.SelectionStart = m.Index;
mTextBox.SelectionLength = m.Length;// -1;
mTextBox.SelectionColor = color;
}
mTextBox.Visible = true;
}
/* Regex mColorizeRegex = new Regex("^[A-Z]+,[A-Za-z \\.']+,[A-Z,a-z ']+,", RegexOptions.Multiline); */
}
public class StringEventArgs : EventArgs
{
/// <summary>
/// The string value
/// </summary>
public string Value { get; set; }
public StringEventArgs(string val)
{
Value = val;
}
}
}