Fixed behavior of FocusedTextBox (special characters and bell).

This commit is contained in:
Lorenz Cuno Klopfenstein 2010-05-26 20:31:03 +02:00
parent b459475cf0
commit d389573363
5 changed files with 308 additions and 269 deletions

View file

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OnTopReplica {
static class EnumerationExtensions {
public static bool Contains<T>(IEnumerable<T> collection, T value){
foreach (var v in collection)
if (v.Equals(value))
return true;
return false;
}
}
}

View file

@ -19,16 +19,46 @@ namespace OnTopReplica {
if (e.KeyCode == Keys.Return) {
OnConfirmInput();
e.Handled = true;
e.SuppressKeyPress = true;
}
else if (e.KeyCode == Keys.Escape) {
OnAbortInput();
e.Handled = true;
e.SuppressKeyPress = true;
}
Console.WriteLine("{0} ({1})", e.KeyCode, e.KeyValue);
base.OnKeyUp(e);
}
//List of characters to ignore on KeyPress events (because they generate bell rings)
char[] _ignoreChars = new char[] {
(char)27, (char)13
};
protected override void OnKeyPress(KeyPressEventArgs e) {
if (EnumerationExtensions.Contains(_ignoreChars, e.KeyChar)) {
e.Handled = true;
}
base.OnKeyPress(e);
}
public event EventHandler ConfirmInput;
protected virtual void OnConfirmInput() {
if (ConfirmInput != null)
ConfirmInput(this, EventArgs.Empty);
var evt = ConfirmInput;
if (evt != null)
evt(this, EventArgs.Empty);
}
public event EventHandler AbortInput;
protected virtual void OnAbortInput() {
var evt = AbortInput;
if (evt != null)
evt(this, EventArgs.Empty);
}
}

View file

@ -105,6 +105,7 @@
</Compile>
<Compile Include="CloneClickEventArgs.cs" />
<Compile Include="CloseRequestEventArgs.cs" />
<Compile Include="EnumerationExtensions.cs" />
<Compile Include="FullscreenMode.cs" />
<Compile Include="Strings.it.Designer.cs">
<DependentUpon>Strings.it.resx</DependentUpon>

View file

@ -54,10 +54,9 @@
this.panel1.Controls.Add(this.groupBox1);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.panel1.Name = "panel1";
this.panel1.Padding = new System.Windows.Forms.Padding(5, 5, 5, 5);
this.panel1.Size = new System.Drawing.Size(233, 292);
this.panel1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.panel1.Size = new System.Drawing.Size(175, 237);
this.panel1.TabIndex = 0;
//
// groupBox1
@ -78,20 +77,17 @@
this.groupBox1.Controls.Add(this.buttonSave);
this.groupBox1.Controls.Add(this.comboBox1);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox1.Location = new System.Drawing.Point(5, 5);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.groupBox1.Location = new System.Drawing.Point(4, 4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.groupBox1.Size = new System.Drawing.Size(223, 282);
this.groupBox1.Size = new System.Drawing.Size(167, 229);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = Strings.RegionsTitle;
this.groupBox1.Text = "Regions";
//
// numH
//
this.numH.Enabled = false;
this.numH.Location = new System.Drawing.Point(145, 150);
this.numH.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.numH.Location = new System.Drawing.Point(109, 122);
this.numH.Maximum = new decimal(new int[] {
100000,
0,
@ -103,15 +99,14 @@
0,
-2147483648});
this.numH.Name = "numH";
this.numH.Size = new System.Drawing.Size(57, 22);
this.numH.Size = new System.Drawing.Size(43, 20);
this.numH.TabIndex = 7;
this.numH.ValueChanged += new System.EventHandler(this.RegionValueChanged);
//
// numW
//
this.numW.Enabled = false;
this.numW.Location = new System.Drawing.Point(145, 118);
this.numW.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.numW.Location = new System.Drawing.Point(109, 96);
this.numW.Maximum = new decimal(new int[] {
100000,
0,
@ -123,15 +118,14 @@
0,
-2147483648});
this.numW.Name = "numW";
this.numW.Size = new System.Drawing.Size(57, 22);
this.numW.Size = new System.Drawing.Size(43, 20);
this.numW.TabIndex = 6;
this.numW.ValueChanged += new System.EventHandler(this.RegionValueChanged);
//
// numY
//
this.numY.Enabled = false;
this.numY.Location = new System.Drawing.Point(31, 150);
this.numY.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.numY.Location = new System.Drawing.Point(23, 122);
this.numY.Maximum = new decimal(new int[] {
100000,
0,
@ -143,15 +137,14 @@
0,
-2147483648});
this.numY.Name = "numY";
this.numY.Size = new System.Drawing.Size(57, 22);
this.numY.Size = new System.Drawing.Size(43, 20);
this.numY.TabIndex = 5;
this.numY.ValueChanged += new System.EventHandler(this.RegionValueChanged);
//
// numX
//
this.numX.Enabled = false;
this.numX.Location = new System.Drawing.Point(31, 118);
this.numX.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.numX.Location = new System.Drawing.Point(23, 96);
this.numX.Maximum = new decimal(new int[] {
100000,
0,
@ -163,17 +156,16 @@
0,
-2147483648});
this.numX.Name = "numX";
this.numX.Size = new System.Drawing.Size(57, 22);
this.numX.Size = new System.Drawing.Size(43, 20);
this.numX.TabIndex = 4;
this.numX.ValueChanged += new System.EventHandler(this.RegionValueChanged);
//
// buttonDone
//
this.buttonDone.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDone.Location = new System.Drawing.Point(135, 246);
this.buttonDone.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonDone.Location = new System.Drawing.Point(101, 200);
this.buttonDone.Name = "buttonDone";
this.buttonDone.Size = new System.Drawing.Size(80, 28);
this.buttonDone.Size = new System.Drawing.Size(60, 23);
this.buttonDone.TabIndex = 9;
this.buttonDone.Text = global::OnTopReplica.Strings.RegionsDoneButton;
this.buttonDone.UseVisualStyleBackColor = true;
@ -182,10 +174,9 @@
// buttonReset
//
this.buttonReset.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonReset.Location = new System.Drawing.Point(8, 246);
this.buttonReset.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonReset.Location = new System.Drawing.Point(6, 200);
this.buttonReset.Name = "buttonReset";
this.buttonReset.Size = new System.Drawing.Size(80, 28);
this.buttonReset.Size = new System.Drawing.Size(60, 23);
this.buttonReset.TabIndex = 8;
this.buttonReset.Text = global::OnTopReplica.Strings.RegionsResetButton;
this.buttonReset.UseVisualStyleBackColor = true;
@ -195,32 +186,29 @@
//
this.label6.AutoSize = true;
this.label6.ForeColor = System.Drawing.SystemColors.ControlDark;
this.label6.Location = new System.Drawing.Point(95, 153);
this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label6.Location = new System.Drawing.Point(71, 124);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(49, 17);
this.label6.Size = new System.Drawing.Size(38, 13);
this.label6.TabIndex = 9;
this.label6.Text = Strings.RegionsHeight;
this.label6.Text = "Height";
//
// label7
//
this.label7.AutoSize = true;
this.label7.ForeColor = System.Drawing.SystemColors.ControlDark;
this.label7.Location = new System.Drawing.Point(95, 121);
this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label7.Location = new System.Drawing.Point(71, 98);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(44, 17);
this.label7.Size = new System.Drawing.Size(35, 13);
this.label7.TabIndex = 8;
this.label7.Text = Strings.RegionsWidth;
this.label7.Text = "Width";
//
// label3
//
this.label3.AutoSize = true;
this.label3.ForeColor = System.Drawing.SystemColors.ControlDark;
this.label3.Location = new System.Drawing.Point(8, 153);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Location = new System.Drawing.Point(6, 124);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(17, 17);
this.label3.Size = new System.Drawing.Size(14, 13);
this.label3.TabIndex = 5;
this.label3.Text = "Y";
//
@ -228,10 +216,9 @@
//
this.label2.AutoSize = true;
this.label2.ForeColor = System.Drawing.SystemColors.ControlDark;
this.label2.Location = new System.Drawing.Point(8, 121);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Location = new System.Drawing.Point(6, 98);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(17, 17);
this.label2.Size = new System.Drawing.Size(14, 13);
this.label2.TabIndex = 4;
this.label2.Text = "X";
//
@ -239,21 +226,19 @@
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(8, 94);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Location = new System.Drawing.Point(6, 76);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(103, 17);
this.label1.Size = new System.Drawing.Size(76, 13);
this.label1.TabIndex = 3;
this.label1.Text = Strings.RegionsCurrentRegion;
this.label1.Text = "Current region:";
//
// buttonDelete
//
this.buttonDelete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDelete.Enabled = false;
this.buttonDelete.Location = new System.Drawing.Point(135, 57);
this.buttonDelete.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonDelete.Location = new System.Drawing.Point(101, 46);
this.buttonDelete.Name = "buttonDelete";
this.buttonDelete.Size = new System.Drawing.Size(80, 28);
this.buttonDelete.Size = new System.Drawing.Size(60, 23);
this.buttonDelete.TabIndex = 3;
this.buttonDelete.Text = global::OnTopReplica.Strings.RegionsDeleteButton;
this.buttonDelete.UseVisualStyleBackColor = true;
@ -262,10 +247,9 @@
// buttonSave
//
this.buttonSave.Enabled = false;
this.buttonSave.Location = new System.Drawing.Point(8, 57);
this.buttonSave.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.buttonSave.Location = new System.Drawing.Point(6, 46);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(80, 28);
this.buttonSave.Size = new System.Drawing.Size(60, 23);
this.buttonSave.TabIndex = 1;
this.buttonSave.Text = global::OnTopReplica.Strings.RegionsSaveButton;
this.buttonSave.UseVisualStyleBackColor = true;
@ -279,10 +263,9 @@
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(8, 23);
this.comboBox1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.comboBox1.Location = new System.Drawing.Point(6, 19);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(206, 24);
this.comboBox1.Size = new System.Drawing.Size(156, 21);
this.comboBox1.TabIndex = 0;
this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.RegionCombo_index);
//
@ -292,25 +275,24 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.textRegionName.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.textRegionName.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.textRegionName.Location = new System.Drawing.Point(8, 59);
this.textRegionName.Margin = new System.Windows.Forms.Padding(4);
this.textRegionName.Location = new System.Drawing.Point(6, 48);
this.textRegionName.Name = "textRegionName";
this.textRegionName.Size = new System.Drawing.Size(118, 22);
this.textRegionName.Size = new System.Drawing.Size(90, 20);
this.textRegionName.TabIndex = 2;
this.textRegionName.Visible = false;
this.textRegionName.Leave += new System.EventHandler(this.Save_lost);
this.textRegionName.ConfirmInput += new System.EventHandler(this.Save_confirm);
this.textRegionName.AbortInput += new System.EventHandler(this.Save_lost);
this.textRegionName.Leave += new System.EventHandler(this.Save_lost);
//
// RegionBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.Black;
this.Controls.Add(this.panel1);
this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
this.MinimumSize = new System.Drawing.Size(213, 222);
this.MinimumSize = new System.Drawing.Size(160, 180);
this.Name = "RegionBox";
this.Size = new System.Drawing.Size(233, 292);
this.Size = new System.Drawing.Size(175, 237);
this.panel1.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();

View file

@ -104,8 +104,15 @@ namespace OnTopReplica {
}
private void DeleteClick(object sender, EventArgs e) {
Settings.Default.SavedRegions.RemoveAt(comboBox1.SelectedIndex);
comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);
if (comboBox1.SelectedIndex < 0)
return;
var origIndex = comboBox1.SelectedIndex;
Settings.Default.SavedRegions.RemoveAt(origIndex);
comboBox1.Items.RemoveAt(origIndex);
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
}
private void SaveClick(object sender, EventArgs e) {