| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- using Client.MirGraphics;
- namespace Client.MirControls
- {
- public sealed class MirInputBox : MirImageControl
- {
- public readonly MirLabel CaptionLabel;
- public readonly MirButton OKButton, CancelButton;
- public readonly MirTextBox InputTextBox;
- public MirInputBox(string message)
- {
- Modal = true;
- Movable = false;
- Index = 660;
- Library = Libraries.Prguse;
- Location = new Point((Settings.ScreenWidth - Size.Width) / 2, (Settings.ScreenHeight - Size.Height) / 2);
- CaptionLabel = new MirLabel
- {
- DrawFormat = TextFormatFlags.WordBreak,
- Location = new Point(25, 25),
- Size = new Size(235, 40),
- Parent = this,
- Text = message,
- };
- InputTextBox = new MirTextBox
- {
- Parent = this,
- Border = true,
- BorderColour = Color.Lime,
- Location = new Point(23, 86),
- Size = new Size(240, 19),
- MaxLength = 50,
- };
- InputTextBox.SetFocus();
- InputTextBox.TextBox.KeyPress += MirInputBox_KeyPress;
- OKButton = new MirButton
- {
- HoverIndex = 201,
- Index = 200,
- Library = Libraries.Title,
- Location = new Point(60, 123),
- Parent = this,
- PressedIndex = 202,
- };
- CancelButton = new MirButton
- {
- HoverIndex = 204,
- Index = 203,
- Library = Libraries.Title,
- Location = new Point(160, 123),
- Parent = this,
- PressedIndex = 205,
- };
- CancelButton.Click += DisposeDialog;
- }
- void MirInputBox_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == (char)Keys.Enter)
- {
- if (OKButton != null && !OKButton.IsDisposed)
- OKButton.InvokeMouseClick(EventArgs.Empty);
- e.Handled = true;
- }
- else if (e.KeyChar == (char)Keys.Escape)
- {
- if (CancelButton != null && !CancelButton.IsDisposed)
- CancelButton.InvokeMouseClick(EventArgs.Empty);
- e.Handled = true;
- }
- }
- void DisposeDialog(object sender, EventArgs e)
- {
- Dispose();
- }
- public override void OnKeyDown(KeyEventArgs e)
- {
- base.OnKeyDown(e);
- e.Handled = true;
- }
- public override void OnKeyUp(KeyEventArgs e)
- {
- base.OnKeyUp(e);
- e.Handled = true;
- }
- public override void OnKeyPress(KeyPressEventArgs e)
- {
- base.OnKeyPress(e);
- if (e.KeyChar == (char)Keys.Escape)
- {
- if (CancelButton != null && !CancelButton.IsDisposed)
- CancelButton.InvokeMouseClick(EventArgs.Empty);
- }
- else if (e.KeyChar == (char)Keys.Enter)
- {
- if (OKButton != null && !OKButton.IsDisposed)
- OKButton.InvokeMouseClick(EventArgs.Empty);
- }
- e.Handled = true;
- }
- public override void Show()
- {
- if (Parent != null) return;
- Parent = MirScene.ActiveScene;
- Highlight();
- for (int i = 0; i < Program.Form.Controls.Count; i++)
- {
- TextBox T = Program.Form.Controls[i] as TextBox;
- if (T != null && T.Tag != null && T.Tag != null)
- ((MirTextBox)T.Tag).DialogChanged();
- }
- }
- #region Disposable
- protected override void Dispose(bool disposing)
- {
- base.Dispose(disposing);
- if (!disposing) return;
- for (int i = 0; i < Program.Form.Controls.Count; i++)
- {
- TextBox T = (TextBox)Program.Form.Controls[i];
- if (T != null && T.Tag != null && T.Tag != null)
- ((MirTextBox)T.Tag).DialogChanged();
- }
- }
- #endregion
- }
- }
|