Lua - forms.textbox() add field to optionally set the textbox to signed, unsigned, or hex values

This commit is contained in:
andres.delikat 2012-07-10 23:09:06 +00:00
parent 3f81bc9cdb
commit 9da0cd3553
3 changed files with 79 additions and 2 deletions

View File

@ -335,6 +335,9 @@
<Compile Include="tools\LuaButton.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="tools\LuaTextBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="tools\LuaWinform.cs">
<SubType>Form</SubType>
</Compile>

View File

@ -1798,7 +1798,7 @@ namespace BizHawk.MultiClient
return (int)label.Handle;
}
public int forms_textbox(object form_handle, object caption = null, object width = null, object height = null, object X = null, object Y = null)
public int forms_textbox(object form_handle, object caption = null, object width = null, object height = null, object boxtype = null, object X = null, object Y = null)
{
LuaWinform form = GetForm(form_handle);
if (form == null)
@ -1806,10 +1806,30 @@ namespace BizHawk.MultiClient
return 0;
}
TextBox textbox = new TextBox();
LuaTextBox textbox = new LuaTextBox();
SetText(textbox, caption);
SetLocation(textbox, X, Y);
SetSize(textbox, X, Y);
if (boxtype != null)
{
switch (boxtype.ToString().ToUpper())
{
case "HEX":
case "HEXADECIMAL":
textbox.SetType(BoxType.HEX);
break;
case "UNSIGNED":
case "UINT":
textbox.SetType(BoxType.UNSIGNED);
break;
case "NUMBER":
case "NUM":
case "SIGNED":
case "INT":
textbox.SetType(BoxType.SIGNED);
break;
}
}
form.Controls.Add(textbox);
return (int)textbox.Handle;
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BizHawk.MultiClient.tools
{
enum BoxType { ALL, SIGNED, UNSIGNED, HEX };
class LuaTextBox : TextBox
{
private BoxType boxType = BoxType.ALL;
public void SetType(BoxType type)
{
boxType = type;
if (type != BoxType.ALL)
{
CharacterCasing = CharacterCasing.Upper;
}
else
{
CharacterCasing = CharacterCasing.Normal;
}
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
SpecificValueBox_KeyPress(this, e);
base.OnKeyPress(e);
}
private void SpecificValueBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == '\b') return;
switch (boxType)
{
case BoxType.UNSIGNED:
if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
e.Handled = true;
break;
case BoxType.SIGNED:
if (!InputValidate.IsValidSignedNumber(e.KeyChar))
e.Handled = true;
break;
case BoxType.HEX:
if (!InputValidate.IsValidHexNumber(e.KeyChar))
e.Handled = true;
break;
}
}
}
}